首页 新闻 会员 周边

反射泛型类型

1
悬赏园豆:5 [已关闭问题] 关闭于 2014-10-18 20:18

由于要反射获取的方法有多个重载

我想到了 "*.GetMethod("xx", new Type[] { yy, zz) });"

可是我要反射的方法是这样定义的

private static Tuple<string, SqlParameter[]> MakeAddCommand<T>(T entity, IEnumerable<PropertyInfo> properties)
private static Tuple<string, SqlParameter[]> MakeAddCommand<T>(object entityId, IEnumerable<T> valueObjects)

这样我反射时,怎么指定这个泛型 T 呢?

就是这个 null 的地址添什么?

.GetMethod("MakeAddCommand", new Type[] { null, typeof(IEnumerable<PropertyInfo>) });
Srouni的主页 Srouni | 初学一级 | 园豆:9
提问于:2014-10-13 16:28
< >
分享
所有回答(1)
0
private static void DisplayGenericType(Type t)
    {
        Console.WriteLine("\r\n {0}", t);
        Console.WriteLine("   Is this a generic type? {0}",
            t.IsGenericType);
        Console.WriteLine("   Is this a generic type definition? {0}",
            t.IsGenericTypeDefinition);

        // Get the generic type parameters or type arguments.
        Type[] typeParameters = t.GetGenericArguments();

        Console.WriteLine("   List {0} type arguments:", 
            typeParameters.Length);
        foreach( Type tParam in typeParameters )
        {
            if (tParam.IsGenericParameter)
            {
                DisplayGenericParameter(tParam);
            }
            else
            {
                Console.WriteLine("      Type argument: {0}",
                    tParam);
            }
        }
    }
  Type d1 = typeof(Dictionary<,>);
DisplayGenericType(d1);

类似上面这种。

悟行 | 园豆:12559 (专家六级) | 2014-10-13 16:46

没看出与我的那个有什么关系啊? 怎么 确定那个 泛型 T ?

支持(0) 反对(0) Srouni | 园豆:9 (初学一级) | 2014-10-13 16:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册