List<MyClass> MyClassPro { get;set; } MyClass obj = new MyClass(); obj.MyClassPro = null;
Consider MyClassPro as NULL. In the Reflection situation, I will not know the class name or property name.
If I try to get a Property Type using GetType, for example,
Type t = obj.GetType();
It returns "System.Collections.Generic.list". But I expect to get a type like MyClass.
I also tried how
foreach(PropertyInfo propertyInfo in obj.GetProperties()) { if(propertyInfo.IsGenericType) { Type t = propertyInfo.GetValue(obj,null).GetType().GetGenericArguments().First(); } }
But it returns an error due to the value of the collection property null, so we cannot get Type.
In this situation, I can get the collection property type.
Please help me!
Thanks at Advance.
source share