I use a delegate and the System.Linq.Expressions.Expression
class to get the PropertyInfo of a property which is overridden in a sub-class. It seems that this technique always gives me the PropertyInfo for the property in the base-class instead of the overridden property.
A work-around for getting hold of the correct PropertyInfo is to use reflection using the name of the original (wrong) PropertyInfo like so: var correctPropertyInfo = mySubClassObject.GetType().GetProperty(wrongPropertyInfo.Name);
This .NET Fiddle illustrates all of this.
Why am I getting the wrong PropertyInfo, and is there a way I can immediately get the correct one without the additional "work-around" step?
Aucun commentaire:
Enregistrer un commentaire