.net - Idiomatic way to test for Generic Type in C# -


if can test basic class types in c#:

bool stringtest = new string() string; // , bool listofstringtest = new list<string>() list<string>; 

how test list of or list know use reflection figure out, there easier , more idiomatic way in c#?

for example, if tested list<int> or list<string> both return true. , nullable<int> , datetime return false. note: using list<> example looking general purpose.

i think way using reflection:

type listtype = new list<string>().gettype(); bool islist = listtype.isgenerictype && list.getgenerictypedefinition() == typeof(list<>); 

Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -