C#反射 创建对象,调用方法

 

namespace TestReflection
{
public class MyCls
{
public void Fun()
{
Console.WriteLine(
"MyCls.Fun invoke.");

}
}
}
/////////////////////////////////////////////////////////
...

using System.Reflection;

namespace TestReflection
{
class Program
{
static void Main(string[] args)
{
Type type
= Assembly.Load("TestReflection").GetType("TestReflection.MyCls");
object obj= Activator.CreateInstance(type);
type.InvokeMember(
"Fun", BindingFlags.Default | BindingFlags.InvokeMethod,
null, obj, new object[] { });

Console.ReadKey();
}
}
}

 

 

 

posted @ 2010-06-27 18:43  庚武  Views(583)  Comments(0Edit  收藏  举报