Do you know the function prototype of foo? You can use the overloaded GetMethod(string, Type[]) if you know it.
For example, you mentioned that there is such a class:
Level a
{
Public void foo (string value);
Public void foo(out string value);
}
If you want to get the above method, use this statement:
1
Type. GetMethod("foo ",new Type[]{ Type of(string)});
If you want one of the following methods, use this statement:
1
Type. GetMethod("foo ",new Type[] { typeof(string)。 MakeByRefType()});
1 class program
2 {
3 static void Main(string[] args)
4 {
five
String content = "main//# 1 variable
6 MethodInfo testMethod = typeof (program). GetMethod("TestMethod ",
Seven binding flags. Static | BindingFlags. Private);
8 if (testMethod! = empty)
9 {
10 // The contents cannot be recovered in the following ways.
1 1 //
12 test method. Invoke(null,new object[]{ content/* # 1 variable */});
13 console. WriteLine (content); // # 1 variable, the output is: main
14 //
15
16
17 object[]invoke args = new object[]{ content/* # 1 variable */};
18 test method. Invoke(null,invoke args);
19 content =(string)invoke args[0]; // #2 variable, bypassing the call, set to content.
20 console. WriteLine (content); // #2 variable, the output is: test
2 1 }
22 }
23
24 Static void Test Method (Reference String Parameter)
25 {
26 arg = "test// #2 variable, want to bypass the main process.
27 }
28 }