c# - How to understand if an object belong to a generic collection through introspection -


let's have reference object. i'd use introspection find out if reference collection don't know (and don't care) generic type of elements holds.

as example:

list<int> l; object referencetolist = l;  if (typeof(referencetolist) == ??) {   //condition true list<int>, list<float> .... } 

any suggestion?

var type = referencetolist.gettype(); if(type.isgenerictype && type.getgenerictypedefinition() == typeof(list<>)) {     // it's list<t> } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

ruby - Nesting modules inside of a Rails eninge gem -

Eclipse formatter for java ending braces -