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