通过反射如何调用类中的私有的、泛型的、多参数的方法?- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- namespace TypeOf_与_GetType
- {
- class Program
- {
- static void Main(string[] args)
- {
- Type t1 = typeof(Person);
- MethodInfo mi3 = t1.GetMethod("SayHelloG<T>", BindingFlags.NonPublic | BindingFlags.Instance);
- object obj = Activator.CreateInstance(t1);
- //...
- Console.ReadKey();
-
- }
- }
- class Person
- {
- private void SayHello()
- {
- Console.WriteLine("Hello!");
- }
- private void SayHelloG<T>(T t)
- {
- Console.WriteLine(t.ToString());
- }
- }
- }
复制代码 |
|