c# - Reflection: Type of item contained in non-generic subclass of generic list -



c# - Reflection: Type of item contained in non-generic subclass of generic list -

public class mylist : list<myclass>

how can type myclass through reflection if have object contains instance of mylist? list can empty, can't mylist[0].gettype().

p.s. can't stop using mylist , straight utilize generic list instead (the situation bit more complicated, , there reasons "hiding" generic argument), can't pick myclass through getgenericarguments().

var elementtype = ( iface in mylist.gettype().getinterfaces() iface.isgenerictype iface.getgenerictypedefinition() == typeof(ilist<>) select iface.getgenericarguments()[0]) .single();

i utilize ilist<t> instead of list. more generic. however, there alter of type implementing multiple ilis<t> versions (such ilist<string> , ilist<int>).

c# reflection

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -