Skip to content

Commit

Permalink
Also match parameters when identifying property
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Apr 9, 2021
1 parent 29dc0df commit 9413924
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Moq/ExpressionExtensions.cs
Expand Up @@ -362,10 +362,15 @@ internal static PropertyInfo GetReboundProperty(this MemberExpression expression
// we "upgrade" to the derived property.
if (property.DeclaringType != expression.Expression.Type)
{
var parameterTypes = new ParameterTypes(property.GetIndexParameters());
var derivedProperty = expression.Expression.Type
.GetMember(property.Name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Cast<PropertyInfo>()
.SingleOrDefault(p => p.PropertyType == property.PropertyType);
.SingleOrDefault(p =>
{
return p.PropertyType == property.PropertyType
&& new ParameterTypes(p.GetIndexParameters()).CompareTo(parameterTypes, true, false);
});
if (derivedProperty != null)
{
if ((derivedProperty.CanRead(out var getter) && getter.GetBaseDefinition() == property.GetGetMethod(true)) ||
Expand Down

0 comments on commit 9413924

Please sign in to comment.