zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    HTML5 WEB SQL
    Android-day04
    Android-day03
    Android-day02
    Android-day01
    java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
    事务管理、整合Junit、整合Web、SSH整合
    AOP、AspectJ、JdbcTemplate
    Spring基础
    Hibernate对连接池的支持
  • 原文地址:https://www.cnblogs.com/kmsfan/p/4560606.html
Copyright © 2011-2022 走看看