Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 444
Elisabeth Avatar asked Sep 02 '12 22:09

Elisabeth


2 Answers

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

like image 141
Alex Paven Avatar answered Sep 18 '22 00:09

Alex Paven


You may try:

Type t = Type.GetType("BLL.MyLayers.TestLayer`1,BLL");
like image 22
petro.sidlovskyy Avatar answered Sep 18 '22 00:09

petro.sidlovskyy