Type.GetType does not work on generic classes?

2019-06-19 00:22发布

问题:

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

t is always null for a generic class.

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

Why is that or do I something wrong?

回答1:

Generic types are compiled using a little trick:

class A<T>
{
}

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

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



回答2:

You may try:

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