Skip to content

Commit

Permalink
Fixed an issue where attributes of the same name cannot be expanded w…
Browse files Browse the repository at this point in the history
…hen subclasses inherit and hide attributes of the parent class (#645)

* Fixed an issue where attributes of the same name cannot be expanded when subclasses inherit and hide attributes of the parent class

* This code fixes an issue where 'History of code' was unable to obtain attributes with the same name as the parent class after the subclass hid the parent class member.
  • Loading branch information
Dean-ZhenYao-Wang authored Aug 12, 2022
1 parent a59ad11 commit 07adec4
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,22 @@ public virtual Expression CreatePropertyValueExpression(QueryBinderContext conte
PropertyInfo propertyInfo = source.Type.GetProperty(propertyName, BindingFlags.DeclaredOnly);
if (propertyInfo == null)
{
propertyInfo = source.Type.GetProperty(propertyName);
/*
History of code:
propertyInfo = source.Type.GetProperty(propertyName);
This code fixes an issue where 'History of code' was unable to obtain attributes with the same name as the parent class after the subclass hid the parent class member.
Such as:
'History of code' cannot get the Key property of the Child.
public class Father
{
public string Key { get; set; }
}
public class Child : Father
{
public new Guid Key { get; set; }
}
*/
propertyInfo = source.Type.GetProperties().Where(m => m.Name.Equals(propertyName)).FirstOrDefault();
}

Expression propertyValue = Expression.Property(source, propertyInfo);
Expand Down

0 comments on commit 07adec4

Please sign in to comment.