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);

 

posted @ 2015-06-08 12:40  yangliwen  阅读(495)  评论(0编辑  收藏  举报
document.getElementById("homeTopTitle").innerText="ღKawaii";