-
Type InvokeMember()用法简介
- 举例:
- Type tDate = typeof(System.DateTime);
- Object result = tDate.InvokeMember("Now",
- BindingFlags.GetProperty, null, null, new Object[0]);
- Console.WriteLine(result.ToString());
-
- 例2:
- TestClass tc = new TestClass ();
- tc.GetType().InvokeMember ("AddUp", BindingFlags.Public |
- BindingFlags.Instance | BindingFlags.CreateInstance,
- null, tc, new object [] {});
- Type t = typeof (TestClass);
- object [] args = new object [] {100.09, 184.45};
- object result = t.InvokeMember ("ComputeSum", BindingFlags.InvokeMethod, null, null, args);
-
-
- t.InvokeMember ("SayHello", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object [] {});
-
- TestClass c = new TestClass ();
- c.GetType().InvokeMember ("AddUp", BindingFlags.InvokeMethod, null, c, new object [] {});
-
- c.GetType().InvokeMember ("AddUp", BindingFlags.Public |
- BindingFlags.Instance | BindingFlags.CreateInstance,
- null, c, new object [] {});
-
-
- result = t.InvokeMember ("Name", BindingFlags.GetField | BindingFlags.GetProperty, null, c, new object [] {});
- result = t.InvokeMember ("Value", BindingFlags.GetField | BindingFlags.GetProperty, null, c, new object [] {});
- result = t.InvokeMember ("Name", BindingFlags.GetField, null, c, new object [] {});
-
- t.InvokeMember ("Name", BindingFlags.SetField, null, c, new object [] {"NewName"});
-
- object[] argValues = new object [] {"Mouse", "Micky"};
- String [] argNames = new String [] {"lastName", "firstName"};
- t.InvokeMember ("PrintName", BindingFlags.InvokeMethod, null, null, argValues, null, null, argNames);
-
- TestClass obj = new TestClass();
- System.Reflection.MethodInfo methInfo =
- obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.SuppressChangeType |
- BindingFlags.InvokeMethod, null,new object[]
- {"Brad","Smith"},null);
-
- methInfo = obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.IgnoreCase |
- BindingFlags.InvokeMethod, null,new object[]
- {"brad","smith"},null);
-
- methInfo = obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.IgnoreReturn |
- BindingFlags.InvokeMethod, null,new object[]
- {"Brad","Smith"},null);
-
- methInfo = obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.OptionalParamBinding |
- BindingFlags.InvokeMethod, null,new object[]
- {"Brad","Smith"},null);
-
-
- methInfo = obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.ExactBinding |
- BindingFlags.InvokeMethod, null,new object[]
- {"Brad","Smith"},null);
-
-
- methInfo = obj.GetType().GetMethod("PrintName");
- methInfo.Invoke(obj,BindingFlags.FlattenHierarchy |
- BindingFlags.InvokeMethod, null,new object[]
- {"Brad","Smith"},null);
-
- Type t3 = typeof (TestClass2);
- t3.InvokeMember ("", BindingFlags.InvokeMethod | BindingFlags.Default, null, new TestClass2(), new object [] {});
- MethodInfo m = t.GetMethod("Swap");
- args = new object[2];
- args[0] = 1;
- args[1] = 2;
- m.Invoke(new TestClass(),args);
-
-
相关阅读:
semijoin链接进行subquery unnesting.
CONCATENATION 引发的性能问题
身份证号码有效性检测算法 ( js版 转 C#版 )
【CS Round #48 (Div. 2 only)】8 Divisible
【CS Round #48 (Div. 2 only)】Water Volume
【CS Round #48 (Div. 2 only)】Game of Chance
【】queue
【】maze
【】minimum
【AtCoder Beginner Contest 073 D】joisino's travel
-
原文地址:https://www.cnblogs.com/tsql/p/8676741.html
Copyright © 2020-2023
润新知