88using System . Reflection ;
99using System . Runtime . CompilerServices ;
1010using System . Text ;
11- using Elasticsearch . Net ;
1211using Nest ;
1312
1413namespace Tests . Benchmarking
@@ -17,27 +16,28 @@ public class NoncachingFieldResolver
1716 {
1817 private readonly IConnectionSettingsValues _settings ;
1918
20- public NoncachingFieldResolver ( IConnectionSettingsValues settings ) => this . _settings = settings ;
19+ public NoncachingFieldResolver ( IConnectionSettingsValues settings ) => _settings = settings ;
2120
2221 public string Resolve ( Field field )
2322 {
24- var name = this . ResolveFieldName ( field ) ;
23+ var name = ResolveFieldName ( field ) ;
2524 if ( field . Boost . HasValue ) name += $ "^{ field . Boost . Value . ToString ( CultureInfo . InvariantCulture ) } ";
2625 return name ;
2726 }
2827
29- internal static bool IsConditionless ( Field field ) => field == null || ( string . IsNullOrEmpty ( field . Name ) && field . Expression == null && field . Property == null ) ;
28+ internal static bool IsConditionless ( Field field ) =>
29+ field == null || string . IsNullOrEmpty ( field . Name ) && field . Expression == null && field . Property == null ;
3030
3131 internal static bool IsConditionless ( PropertyName property ) =>
32- property == null || ( string . IsNullOrEmpty ( property . Name ) && property . Expression == null && property . Property == null ) ;
32+ property == null || string . IsNullOrEmpty ( property . Name ) && property . Expression == null && property . Property == null ;
3333
3434 private string ResolveFieldName ( Field field )
3535 {
3636 if ( IsConditionless ( field ) ) return null ;
3737 if ( ! string . IsNullOrEmpty ( field . Name ) ) return field . Name ;
38- if ( field . Expression != null && ! field . CachableExpression ) return this . Resolve ( field . Expression , field . Property ) ;
38+ if ( field . Expression != null && ! field . CachableExpression ) return Resolve ( field . Expression , field . Property ) ;
3939
40- var fieldName = this . Resolve ( field . Expression , field . Property ) ;
40+ var fieldName = Resolve ( field . Expression , field . Property ) ;
4141 return fieldName ;
4242 }
4343
@@ -46,12 +46,9 @@ public string Resolve(PropertyName property)
4646 if ( IsConditionless ( property ) ) return null ;
4747 if ( ! string . IsNullOrEmpty ( property . Name ) ) return property . Name ;
4848
49- if ( property . Expression != null && ! property . CacheableExpression )
50- {
51- return this . Resolve ( property . Expression , property . Property ) ;
52- }
49+ if ( property . Expression != null && ! property . CacheableExpression ) return Resolve ( property . Expression , property . Property ) ;
5350
54- var propertyName = this . Resolve ( property . Expression , property . Property , true ) ;
51+ var propertyName = Resolve ( property . Expression , property . Property , true ) ;
5552 return propertyName ;
5653 }
5754
@@ -72,16 +69,16 @@ private string Resolve(Expression expression, MemberInfo member, bool toLastToke
7269
7370 internal class FieldExpressionVisitor : ExpressionVisitor
7471 {
75- private readonly Stack < string > _stack = new Stack < string > ( ) ;
76-
7772 private readonly IConnectionSettingsValues _settings ;
73+ private readonly Stack < string > _stack = new Stack < string > ( ) ;
7874
7975 public FieldExpressionVisitor ( IConnectionSettingsValues settings ) => _settings = settings ;
8076
8177 public string Resolve ( Expression expression , bool toLastToken = false )
8278 {
83- this . Visit ( expression ) ;
79+ Visit ( expression ) ;
8480 if ( toLastToken ) return Enumerable . Last < string > ( _stack ) ;
81+
8582 return Enumerable . Aggregate < string , StringBuilder > ( _stack , new StringBuilder ( ) ,
8683 ( sb , name ) =>
8784 ( sb . Length > 0 ? sb . Append ( "." ) : sb ) . Append ( name ) )
@@ -95,7 +92,7 @@ public string Resolve(MemberInfo info)
9592
9693 var name = info . Name ;
9794
98- if ( this . _settings . PropertyMappings . TryGetValue ( info , out var propertyMapping ) )
95+ if ( _settings . PropertyMappings . TryGetValue ( info , out var propertyMapping ) )
9996 return propertyMapping . Name ;
10097
10198 var att = ElasticsearchPropertyAttributeBase . From ( info ) ;
@@ -108,7 +105,8 @@ public string Resolve(MemberInfo info)
108105 protected override Expression VisitMember ( MemberExpression expression )
109106 {
110107 if ( _stack == null ) return base . VisitMember ( expression ) ;
111- var name = this . Resolve ( expression . Member ) ;
108+
109+ var name = Resolve ( expression . Member ) ;
112110 _stack . Push ( name ) ;
113111 return base . VisitMember ( expression ) ;
114112 }
@@ -121,7 +119,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall)
121119 var callingMember = new ReadOnlyCollection < Expression > (
122120 new List < Expression > { { methodCall . Arguments . First ( ) } }
123121 ) ;
124- base . Visit ( callingMember ) ;
122+ Visit ( callingMember ) ;
125123 return methodCall ;
126124 }
127125 else if ( methodCall . Method . Name == "get_Item" && methodCall . Arguments . Any ( ) )
@@ -130,23 +128,18 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall)
130128 var isDict =
131129 typeof ( IDictionary ) . IsAssignableFrom ( t )
132130 || typeof ( IDictionary < , > ) . IsAssignableFrom ( t )
133- || ( t . GetTypeInfo ( ) . IsGenericType && t . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) ) ;
131+ || t . GetTypeInfo ( ) . IsGenericType && t . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) ;
132+
133+ if ( ! isDict ) return base . VisitMethodCall ( methodCall ) ;
134134
135- if ( ! isDict )
136- {
137- return base . VisitMethodCall ( methodCall ) ;
138- }
139135 VisitConstantOrVariable ( methodCall , _stack ) ;
140- this . Visit ( methodCall . Object ) ;
136+ Visit ( methodCall . Object ) ;
141137 return methodCall ;
142138 }
143139 else if ( IsLinqOperator ( methodCall . Method ) )
144140 {
145- for ( int i = 1 ; i < methodCall . Arguments . Count ; i ++ )
146- {
147- this . Visit ( methodCall . Arguments [ i ] ) ;
148- }
149- this . Visit ( methodCall . Arguments [ 0 ] ) ;
141+ for ( var i = 1 ; i < methodCall . Arguments . Count ; i ++ ) Visit ( methodCall . Arguments [ i ] ) ;
142+ Visit ( methodCall . Arguments [ 0 ] ) ;
150143 return methodCall ;
151144 }
152145 return base . VisitMethodCall ( methodCall ) ;
0 commit comments