使用反射:
如果我有一个类型的实例X<Y>(我不知道到底Y是什么),因为X它是一个泛型类型 ( X<T>),我如何获得一个属性的值Y?
就像是:
Type yType = currentObject.GetType().GetGenericArguments()[0];
// How do I get yInstance???
var yInstance = Convert.ChangeType(???, yType);
我需要去:
object requiredValue = yType.GetProperty("YProperty").GetValue(yInstance, null);