@@ -1617,45 +1617,33 @@ static Exception IncompatibleOperandsError(string opName, Expression left, Expre
1617
1617
static MemberInfo FindPropertyOrField ( Type type , string memberName , bool staticAccess )
1618
1618
{
1619
1619
#if ! ( NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD )
1620
- BindingFlags flags = BindingFlags . Public | BindingFlags . DeclaredOnly |
1621
- ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
1620
+ BindingFlags flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
1622
1621
foreach ( Type t in SelfAndBaseTypes ( type ) )
1623
1622
{
1624
- MemberInfo [ ] members = t . FindMembers ( MemberTypes . Property | MemberTypes . Field ,
1625
- flags , Type . FilterNameIgnoreCase , memberName ) ;
1626
- if ( members . Length != 0 ) return members [ 0 ] ;
1623
+ MemberInfo [ ] members = t . FindMembers ( MemberTypes . Property | MemberTypes . Field , flags , Type . FilterNameIgnoreCase , memberName ) ;
1624
+ if ( members . Length != 0 )
1625
+ return members [ 0 ] ;
1627
1626
}
1628
1627
return null ;
1629
1628
#else
1630
1629
foreach ( Type t in SelfAndBaseTypes ( type ) )
1631
1630
{
1631
+ // Try to find a property with the specified memberName
1632
1632
MemberInfo member = t . GetTypeInfo ( ) . DeclaredProperties . FirstOrDefault ( x => x . Name . ToLowerInvariant ( ) == memberName . ToLowerInvariant ( ) ) ;
1633
+ if ( member != null )
1634
+ return member ;
1633
1635
1634
- if ( member == null )
1635
- member = t . GetTypeInfo ( ) . DeclaredFields . FirstOrDefault ( x => ( x . IsStatic || ! staticAccess ) && x . Name . ToLowerInvariant ( ) == memberName . ToLowerInvariant ( ) ) ;
1636
+ // If no property is found, try to get a field with the specified memberName
1637
+ member = t . GetTypeInfo ( ) . DeclaredFields . FirstOrDefault ( x => ( x . IsStatic || ! staticAccess ) && x . Name . ToLowerInvariant ( ) == memberName . ToLowerInvariant ( ) ) ;
1638
+ if ( member != null )
1639
+ return member ;
1636
1640
1637
- return member ;
1641
+ // No property or field is found, try the base type.
1638
1642
}
1639
1643
return null ;
1640
1644
#endif
1641
1645
}
1642
1646
1643
- /*
1644
- *
1645
- BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly |
1646
- (staticAccess ? BindingFlags.Static : BindingFlags.Instance);
1647
- foreach (Type t in SelfAndBaseTypes(type))
1648
- {
1649
- MemberInfo[] members = t.FindMembers(MemberTypes.Method,
1650
- flags, Type.FilterNameIgnoreCase, methodName);
1651
- int count = FindBestMethod(members.Cast<MethodBase>(), args, out method);
1652
- if (count != 0) return count;
1653
- }
1654
- method = null;
1655
- return 0;
1656
-
1657
- */
1658
-
1659
1647
int FindMethod ( Type type , string methodName , bool staticAccess , Expression [ ] args , out MethodBase method )
1660
1648
{
1661
1649
#if ! ( NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD )
0 commit comments