StructureMap.dll 中的 GetInstance 重载 + 如何利用 反射动态创建泛型类
public static T GetInstance<T>(ExplicitArguments args); // // Summary: // Creates a new instance of the requested type T using the supplied Instance. // Mostly used internally // // Parameters: // instance: public static T GetInstance<T>(Instance instance); // // Summary: // Creates or finds the default instance of the pluginType // // Parameters: // pluginType: public static object GetInstance(Type pluginType); // // Summary: // Creates a new instance of the requested type using the supplied Instance. // Mostly used internally // // Parameters: // targetType: // // instance: public static object GetInstance(Type targetType, Instance instance);
用 反射动态 创建泛型类的方法 :
var d1 = Type.GetType("GenericTest.TaskA`1"); // GenericTest was my namespace, add yours Type[] typeArgs = { typeof(Item) }; var makeme = d1.MakeGenericType(typeArgs); object o = Activator.CreateInstance(makeme);
作者:
KMSFan
出处:http://www.cnblogs.com/kmsfan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
欢迎大家加入KMSFan之家,以及访问我的优酷空间!
出处:http://www.cnblogs.com/kmsfan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
欢迎大家加入KMSFan之家,以及访问我的优酷空间!

浙公网安备 33010602011771号