[英]how to implement interface through reflection in c#
My Code is like 我的代码就像
Assembly assemblyX = Assembly.Load("xyz.abc.DataObjects"); Type t = assemblyX.GetType("xyz.abc.DataObjects." + ValueStr);
Everything is good till this point. 到目前为止,一切都很好。 Now i want to implement interface on 't' which is 'xDataObject' and require a generic ie "CurrentDataObject" in < > operators like
xDataObject<CurrentDataObject>
. 现在,我想在't'上实现接口,该接口为'xDataObject',并且在
xDataObject<CurrentDataObject>
这样的<>运算符中需要通用的即“ CurrentDataObject”。 This interface consists many member functions, which I want to use in reflection. 这个接口包含许多成员函数,我想在反射中使用它们。 According to my research on it, the problem is in this next line, which works fine until we don't need interface ie
根据我对它的研究,问题出在下一行,在我们不需要界面之前,它可以正常工作,即
Object objClass = (Object)Activator.CreateInstance(t);
Help me. 帮我。 I'm new to Generics.
我是泛型新手。 Thank you.
谢谢。
There is no native solution for what you want as generic checking is made at compile time. 编译时进行泛型检查,因此您没有想要的本机解决方案。 At runtime you must use
dynamic
in your code or the previously recommended dll. 在运行时,您必须在代码或以前推荐的dll中使用
dynamic
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.