Elisabeth
Elisabeth

Reputation: 21226

Type.GetType does not work on generic classes?

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?

Upvotes: 7

Views: 2638

Answers (2)

Alex Paven
Alex Paven

Reputation: 5549

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

Upvotes: 11

petro.sidlovskyy
petro.sidlovskyy

Reputation: 5103

You may try:

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

Upvotes: 3

Related Questions