Can reflection find my collection type at runtime?

Possible duplicate:
How to determine that an object is a general collection, and what types does it contain?

Hello

I have a generic method that returns a IEnumerable<T> , my problem is that I am not a type T at compile time, I played with reflection but cannot get it before work.

Here is the code:

 Type myType = prop.ReflectedType; MethodInfo mi = typeof(GenericDataMapper).GetMethod("GetList").MakeGenericMethod(myType); var Result = mi.Invoke(this, new object[] {"myString"}) private IEnumerable<T> Getlist<T>(string fieldname) where T: class { //The method of course does something.... Return new List<T>(); } 

Anyone got it?

+4
source share

Source: https://habr.com/ru/post/1336609/


All Articles