the important thing is not to stop questioning

导航

 

反射

var a = Assembly.GetExecutingAssembly();
Type type = a.GetType("CLRTest.ReflectClass");
var instance = Activator.CreateInstance(type);
var method= type.GetMethod("Add");
method.Invoke(instance, new object[] { 1, 2 });

dynamic

var a= Assembly.GetExecutingAssembly();
Type type = a.GetType("CLRTest.ReflectClass");
dynamic instance=Activator.CreateInstance(type);
var sum=instance.Add(1,2);

语法相对简化一些,性能上还未测试。

posted on 2016-04-27 16:05  qook  阅读(135)  评论(0编辑  收藏  举报