Type.GetType 不适用于泛型类? [英] Type.GetType does not work on generic classes?

查看:44
本文介绍了Type.GetType 不适用于泛型类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Type t = Type.GetType("BLL.MyLayers.TestLayer,BLL");

t 对于泛型类始终为 null.

t is always null for a generic class.

当我尝试获取普通类的类型时,t 不为空.

When I try to get the type for a normal class t is not null.

为什么会这样,或者我有什么问题?

Why is that or do I something wrong?

推荐答案

使用一个小技巧编译泛型类型:

Generic types are compiled using a little trick:

class A<T>
{
}

var aa = Type.GetType("ConsoleApplication1.A`1");

请注意,撇号不是引号,而是 1 键左侧的键(在大多数键盘上).

Note that the apostrophe isn't a quote, but the key to the left of the 1 key (on most keyboards).

这篇关于Type.GetType 不适用于泛型类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆