.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
Post a Comment