反射中的对象创建 [英] Object creaton in Reflection
本文介绍了反射中的对象创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一个项目程序集加载到另一个项目中,并且在那里创建类的对象.但是那些类的构造函数调用一个导致异常的静态方法,因为异常已被调用的目标所触发"
请汇总.........
I am loading one projects assembly in another project and there i am creating object of the classes. But those class''s constructors calls one static method which causes exception as "Exception has been thrwon by target of an invocation"
Please sugest.........
推荐答案
我创建测试代码
i create the test code
var type = typeof(TestClass);
var instance = Activator.CreateInstance(type);
((TestClass)instance).Print();
public class TestClass
{
public TestClass()
{
AnotherTestClass.Print();
}
public void Print()
{
Debug.WriteLine("### TestClass.Print Method Invoked");
}
}
public class AnotherTestClass
{
public static void Print()
{
Debug.WriteLine("### AnotherTestClass.Print Method Invoked");
}
}
而且效果很好,我认为问题出在您调用的那个静态方法中.
and it worked fine, i think the problem is in that static method that you call.
这篇关于反射中的对象创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文