reflection

How do I list the public methods of a package in golang [duplicate]

女生的网名这么多〃 提交于 2020-01-11 06:52:07
问题 This question already has answers here : Call functions with special prefix/suffix (2 answers) Closed 2 years ago . How to list the package's public methods in golang? main.go package main func main() { // list all public methods in here } libs/method.go package libs func Resut1() { fmt.Println("method Result1") } func Resut2() { fmt.Println("method Result2") } 回答1: I can't answer with a 100% confidence, but I don't think this is possible to do in Go, at least quite as described. This

Using FieldInfo.SetValue vs LINQ expressions to set a field in a struct

泪湿孤枕 提交于 2020-01-11 05:40:08
问题 I want to set private fields using LINQ expressions. I have this code: //parameter "target", the object on which to set the field `field` ParameterExpression targetExp = Expression.Parameter(typeof(object), "target"); //parameter "value" the value to be set in the `field` on "target" ParameterExpression valueExp = Expression.Parameter(typeof(object), "value"); //cast the target from object to its correct type Expression castTartgetExp = Expression.Convert(targetExp, type); //cast the value to

Why a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException if the invoked method is there?

烈酒焚心 提交于 2020-01-11 04:23:04
问题 I have the following code which creates a dynamic object that is assigned to the smtpClient variable. public class TranferManager { public void Tranfer(Account from, Account to, Money amount) { // Perform the required actions var smtpClient = New.SmtpClient(); smtpClient.Send("info@bank.com", "from.Email", "Tranfer", "?"); // In the previous line I get a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException // with the description = "'object' does not contain a definition for 'Send'" } }

Get only public methods of a class using Java reflection

与世无争的帅哥 提交于 2020-01-11 04:19:08
问题 I'm trying to use reflection to grab all public methods that are declared explicitly in the class (so c.getMethods() won't work since it grabs superclass methods too). I can use Method[] allMethods = c.getDeclaredMethods(); to grab methods from just that class, but I only want to use public ones. At this point, I'm trying to grab modifiers and do certain actions based on this, but for some reason the modifier value shown in the debugger and the modifier value output isn't the same. For

copy one object to another

梦想的初衷 提交于 2020-01-11 04:13:08
问题 .net 3.5, VS 2010... this is for an asp.net website. I have an class called Agency. there is a second class called Agency_Queries. Agency_Queries inhertis the Agency class. I'm trying to create a function that will copy the like properties in Agency to Agency_Queries. I figured out how to do that.. but when i try to make it more generic so that i can pass in my class name and lists i'm doing something wrong. So if there is an list(of Agency) that needs to be copied to list(of Agency_Queries)

detecting native objects with reflection

杀马特。学长 韩版系。学妹 提交于 2020-01-11 03:16:10
问题 I am working with a reflection based object translator. it basically loops through properties of an object, and assigns the values to properties with the same name/type on the translated object. ObjectA.Name = "Joe" translates to: ObjectB.Name = "Joe" I need to put a special case, for when a property is a custom class such as: ObjectA.Address i was hoping i could detect such properties with IsClass flag of PropertyType propInfo.PropertyType.IsClass but this flag also appears to return true

Is it possible to enumerate all methods and properties that are available via Invoke() of an [ADSI] object?

萝らか妹 提交于 2020-01-11 01:41:40
问题 I am curious if someone can describe how to enumerate ADSI methods available via a bound instance as [ADSI]$instance.psbase.Invoke() ? Research has turned up "refer to the docs for the ADSI interface". but I am not particularly happy with that answer. If I instantiate with: [ADSI]$lhost_group="WinNT://./Administrators,group" Then attempt: @($lhost_group.psbase.Invoke("Members")) | foreach-object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)} Powershell will return the

how to pass multiple parameters to a method in java reflections

半世苍凉 提交于 2020-01-10 14:44:26
问题 Hi i am using reflections to achieve something. I have been given class name, method name of that class and parameter values that needs to be passed to that method in a file(Take any file. Not a constraint). I have to call that method with the parameters. This methods do not return anything. There is a huge list of methods in this classes and parameter list of each varies. E.g: method1(String, String, int, boolean) method1(String, int, boolean) and likewise i have different permutations and

How to invoke parent private method from child? [duplicate]

爱⌒轻易说出口 提交于 2020-01-10 13:32:47
问题 This question already has answers here : How can a derived class invoke private method of base class? (7 answers) Closed 4 years ago . public class A{ private int getC(){ return 0; } } public class B extends A{ public static void main(String args[]){ B = new B(); //here I need to invoke getC() } } Can you please tell me if it is possible to do sush thing via reflection in java? 回答1: class A{ private void a(){ System.out.println("private of A called"); } } class B extends A{ public void callAa

How to get the value of a private static field from a class?

时光怂恿深爱的人放手 提交于 2020-01-10 11:51:53
问题 Is there any way to get value of private static field from known class using reflection? 回答1: Yes. Type type = typeof(TheClass); FieldInfo info = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Static); object value = info.GetValue(null); This is for a field. For a property, change type.GetField to type.GetProperty . You can also access private methods in a similar fashion. 回答2: I suppose someone should ask whether this is a good idea or not? It creates a dependency on the private