@@ -1566,7 +1566,7 @@ private static MemberInfo GetMemberInfoFromLambda<TMember>(Expression<Func<TClas
1566
1566
case MemberTypes . Property :
1567
1567
if ( memberInfo . DeclaringType . IsInterface )
1568
1568
{
1569
- memberInfo = ResolveExplicitProperty ( memberInfo , typeof ( TClass ) ) ;
1569
+ memberInfo = FindPropertyImplementation ( ( PropertyInfo ) memberInfo , typeof ( TClass ) ) ;
1570
1570
}
1571
1571
break ;
1572
1572
default :
@@ -1585,45 +1585,32 @@ private static string GetMemberNameFromLambda<TMember>(Expression<Func<TClass, T
1585
1585
return GetMemberInfoFromLambda ( memberLambda ) . Name ;
1586
1586
}
1587
1587
1588
- private static PropertyInfo ResolveExplicitProperty ( MemberInfo interfaceMemberInfo , Type targetType )
1588
+ private static PropertyInfo FindPropertyImplementation ( PropertyInfo interfacePropertyInfo , Type actualType )
1589
1589
{
1590
- var interfaceType = interfaceMemberInfo . DeclaringType ;
1590
+ var interfaceType = interfacePropertyInfo . DeclaringType ;
1591
1591
1592
1592
// An interface map must be used because because there is no
1593
1593
// other officially documented way to derive the explicitly
1594
1594
// implemented property name.
1595
- var interfaceMap = targetType . GetInterfaceMap ( interfaceType ) ;
1595
+ var interfaceMap = actualType . GetInterfaceMap ( interfaceType ) ;
1596
1596
1597
- var interfacePropertyAccessors = ( ( PropertyInfo ) interfaceMemberInfo ) . GetAccessors ( true ) ;
1597
+ var interfacePropertyAccessors = interfacePropertyInfo . GetAccessors ( true ) ;
1598
1598
1599
- var targetPropertyAccessors = interfacePropertyAccessors . Select ( accessor =>
1599
+ var actualPropertyAccessors = interfacePropertyAccessors . Select ( interfacePropertyAccessor =>
1600
1600
{
1601
- var index = Array . IndexOf < MethodInfo > ( interfaceMap . InterfaceMethods , accessor ) ;
1601
+ var index = Array . IndexOf < MethodInfo > ( interfaceMap . InterfaceMethods , interfacePropertyAccessor ) ;
1602
1602
1603
1603
return interfaceMap . TargetMethods [ index ] ;
1604
- } ) . ToArray ( ) ;
1604
+ } ) ;
1605
1605
1606
1606
// Binding must be done by accessor methods because interface
1607
1607
// maps only map accessor methods and do not map properties.
1608
- return targetType . GetProperties ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic )
1608
+ return actualType . GetProperties ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic )
1609
1609
. Single ( propertyInfo =>
1610
1610
{
1611
- var accessors = propertyInfo . GetAccessors ( true ) ;
1612
-
1613
- if ( accessors . Length != targetPropertyAccessors . Length )
1614
- {
1615
- return false ;
1616
- }
1617
-
1618
- for ( var i = 0 ; i < accessors . Length ; ++ i )
1619
- {
1620
- if ( ! targetPropertyAccessors . Contains ( accessors [ i ] ) )
1621
- {
1622
- return false ;
1623
- }
1624
- }
1625
-
1626
- return true ;
1611
+ // we are looking for a property that implements all the required accessors
1612
+ var propertyAccessors = propertyInfo . GetAccessors ( true ) ;
1613
+ return actualPropertyAccessors . All ( x => propertyAccessors . Contains ( x ) ) ;
1627
1614
} ) ;
1628
1615
}
1629
1616
}
0 commit comments