@@ -40,7 +40,7 @@ static Expression AggregatePath(string path, Expression parameter)
4040 {
4141 return path . Split ( '.' )
4242 . Aggregate ( parameter , ( current , property ) =>
43- Expression . MakeMemberAccess ( current , GetPropertyOrField ( current . Type , property ) ) ) ;
43+ Expression . MakeMemberAccess ( current , GetPropertyOrField ( current . Type , property ) ! ) ) ;
4444 }
4545 catch ( ArgumentException exception )
4646 {
@@ -53,35 +53,22 @@ static Expression AggregatePath(string path, Expression parameter)
5353 /// </summary>
5454 /// <param name="type">Type to retrieve property from</param>
5555 /// <param name="propertyOrFieldName">Name of property or field</param>
56- static MemberInfo GetPropertyOrField ( Type type , string propertyOrFieldName )
56+ static MemberInfo ? GetPropertyOrField ( Type type , string propertyOrFieldName )
5757 {
5858 // Member search binding flags
5959 const BindingFlags bindingFlagsPublic = BindingFlags . Instance | BindingFlags . Public | BindingFlags . IgnoreCase | BindingFlags . FlattenHierarchy ;
6060 const BindingFlags bindingFlagsNonPublic = BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . IgnoreCase | BindingFlags . FlattenHierarchy ;
6161
6262 // Attempt to get the public property
63- MemberInfo ? propertyOrField = type . GetProperty ( propertyOrFieldName , bindingFlagsPublic ) ;
63+ var propertyOrField = type . GetProperty ( propertyOrFieldName , bindingFlagsPublic ) ?? ( MemberInfo ? ) type . GetField ( propertyOrFieldName , bindingFlagsPublic ) ;
6464
6565 // If not found
66- if ( propertyOrField is null )
67- {
68- // Attempt to get public field
69- propertyOrField = type . GetField ( propertyOrFieldName , bindingFlagsPublic ) ;
70- }
7166
7267 // If not found
73- if ( propertyOrField is null )
74- {
75- // Attempt to get non-public property
76- propertyOrField = type . GetProperty ( propertyOrFieldName , bindingFlagsNonPublic ) ;
77- }
68+ propertyOrField ??= type . GetProperty ( propertyOrFieldName , bindingFlagsNonPublic ) ;
7869
7970 // If not found
80- if ( propertyOrField is null )
81- {
82- // Attempt to get non-public property
83- propertyOrField = type . GetField ( propertyOrFieldName , bindingFlagsNonPublic ) ;
84- }
71+ propertyOrField ??= type . GetField ( propertyOrFieldName , bindingFlagsNonPublic ) ;
8572
8673 // If property/ field was not resolved
8774 if ( propertyOrField == null && type . IsInterface )
0 commit comments