I've been given:
-
A class "
T < / Code> "which implements the properties decorated with those qualities which I am interested in. -
A
PropertyInfo"p" (1) An interface related to "I" Representing a property, which implementsT, (2) a base class "B" inherited fromT, Or (3) classT. -
p.DeclaringType == type (t)this is a trivial matter . By the time I do not find a match, I can repeat through the properties of
T. Example:Return Type (T) .GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic). FirstOrDefault (property = & gt; property == p) -
p.DeclaringType == type (I)whereIis an interface that implementsTThis is more complex. I found that I can use an interface mapping to find the related implementation of
pinp. It seems like this, but what works here:if (p.DeclaringType.IsInterface & Typef (T) .GetInterfaces (). This includes (P. Delivering Type)) {interface mapping map = typef (t) .GetInterfaceMap (p.DeclaringType); MethodInfo getMethod = p.GetGetMethod (); (Int i = 0; I & lt; map.InterfaceMethods.Length; i ++) {If (map.InterfaceMethods [i] == getMethod) {MethodInfo target = map.TargetMethods [i]; Return Typef (T) .GetProperties (BindingFlag.Instens | BindingFlag.Policy | Compulsive Flag Nonpolic) .FirstOrDefault (property = & gt; property.GetGetMethod () == Target); }} -
p.DeclaringType == type (b)wherebis a classT getsI have not yet figured out how to override the virtual property to identify the property on
T< Code> p definedTs base classb. - in Case 3 on
PropertyInfoHow can I get code> T that property toponb? - Is there a better way of doing all three? Perhaps the way to unite three cases.
I (or property in T), even if the declared declaration of p is an interface that implements T Or a class that is derived from T That's why I want a way to get from p to PropertyInfo which is actually present on T . Thus it seems that there are 3 cases:
So my questions are
I think you are missing a case: it is possible that Do not overwrite property with B , not overwritten (unless you are not certain that it will not be in your specific scenario).
Anyway, you have to search for properties by name, using typef (t). GETProperty , because in a given class there can not be 2 properties with the same name (unlike the methods, which can have many overloads). However, you need to check this case where inherited from T hidden property B , new Modifier To handle that case, you can see the property of the Recipient Method (derived from the GetGetMethod ) property: If the NewSlot flag exists, So the heritage hides the recipient.
Comments
Post a Comment