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" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -