Is it possible to get the type of a class from a property instance
I tried the following
var model = new MyModel("SomeValueForMyProperty")
Type declaringType = model.MyProperty.GetType().DeclaringType
But the result is always not for both DeclaringType and ReflectedType
There is no direct link from a
Type
to a class declaring a property of that type.You'll need to use a
PropertyInfo
: