@@ -857,9 +857,12 @@ private Expression ParseIdentifier()
857
857
{
858
858
_textParser . ValidateToken ( TokenId . Identifier ) ;
859
859
860
- if ( _keywordsHelper . TryGetValue ( _textParser . CurrentToken . Text , out object ? value ) &&
861
- // Prioritize property or field over the type
862
- ! ( value is Type && _it != null && FindPropertyOrField ( _it . Type , _textParser . CurrentToken . Text , false ) != null ) )
860
+ var isValidKeyWord = _keywordsHelper . TryGetValue ( _textParser . CurrentToken . Text , out var value ) ;
861
+
862
+ var extraCondition = ! _parsingConfig . PrioritizePropertyOrFieldOverTheType ||
863
+ ( _parsingConfig . PrioritizePropertyOrFieldOverTheType && ! ( value is Type && _it != null && FindPropertyOrField ( _it . Type , _textParser . CurrentToken . Text , false ) != null ) ) ;
864
+
865
+ if ( isValidKeyWord && extraCondition )
863
866
{
864
867
if ( value is Type typeValue )
865
868
{
@@ -1711,9 +1714,13 @@ private Expression ParseMemberAccess(Type? type, Expression? expression)
1711
1714
return Expression . Field ( expression , field ) ;
1712
1715
}
1713
1716
1714
- if ( ! _parsingConfig . DisableMemberAccessToIndexAccessorFallback && expression != null )
1717
+ // #357 #662
1718
+ var extraCheck = ! _parsingConfig . PrioritizePropertyOrFieldOverTheType ||
1719
+ _parsingConfig . PrioritizePropertyOrFieldOverTheType && expression != null ;
1720
+
1721
+ if ( ! _parsingConfig . DisableMemberAccessToIndexAccessorFallback && extraCheck )
1715
1722
{
1716
- var indexerMethod = expression . Type . GetMethod ( "get_Item" , new [ ] { typeof ( string ) } ) ;
1723
+ var indexerMethod = expression ? . Type . GetMethod ( "get_Item" , new [ ] { typeof ( string ) } ) ;
1717
1724
if ( indexerMethod != null )
1718
1725
{
1719
1726
return Expression . Call ( expression , indexerMethod , Expression . Constant ( id ) ) ;
@@ -2139,11 +2146,12 @@ private static Exception IncompatibleOperandsError(string opName, Expression lef
2139
2146
private MemberInfo ? FindPropertyOrField ( Type type , string memberName , bool staticAccess )
2140
2147
{
2141
2148
#if ! ( NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD )
2142
- BindingFlags flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
2149
+ var extraBindingFlag = _parsingConfig . PrioritizePropertyOrFieldOverTheType && staticAccess ? BindingFlags . Static : BindingFlags . Instance ;
2150
+ var bindingFlags = BindingFlags . Public | BindingFlags . DeclaredOnly | extraBindingFlag ;
2143
2151
foreach ( Type t in TypeHelper . GetSelfAndBaseTypes ( type ) )
2144
2152
{
2145
2153
var findMembersType = _parsingConfig ? . IsCaseSensitive == true ? Type . FilterName : Type . FilterNameIgnoreCase ;
2146
- var members = t . FindMembers ( MemberTypes . Property | MemberTypes . Field , flags , findMembersType , memberName ) ;
2154
+ var members = t . FindMembers ( MemberTypes . Property | MemberTypes . Field , bindingFlags , findMembersType , memberName ) ;
2147
2155
2148
2156
if ( members . Length != 0 )
2149
2157
{
0 commit comments