Skip to content

Commit 5030c4c

Browse files
skncvMpdreamz
authored andcommitted
Fix AppendSuffix to work with different expressions and updated test (#2338)
AppendSuffix should work with any expression instead of just member access expressions Closes #2331
1 parent 09470d3 commit 5030c4c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Nest/CommonAbstractions/Extensions/ExpressionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public SuffixExpressionVisitor(string suffix)
3131
this.suffix = suffix;
3232
}
3333

34-
protected override Expression VisitMember(MemberExpression node)
34+
public override Expression Visit(Expression node)
3535
{
3636
return Expression.Call(
3737
typeof(SuffixExtensions),

src/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ public void AppendingSuffixToExpressions()
284284
p => p.Name,
285285
p => p.Description,
286286
p => p.CuratedTags.First().Name,
287-
p => p.LeadDeveloper.FirstName
287+
p => p.LeadDeveloper.FirstName,
288+
p => p.Metadata["hardcoded"]
288289
};
289290

290291
/** and we want to append the suffix "raw" to each */
@@ -295,6 +296,17 @@ public void AppendingSuffixToExpressions()
295296
Expect("description.raw").WhenSerializing(fieldExpressions[1]);
296297
Expect("curatedTags.name.raw").WhenSerializing(fieldExpressions[2]);
297298
Expect("leadDeveloper.firstName.raw").WhenSerializing(fieldExpressions[3]);
299+
Expect("metadata.hardcoded.raw").WhenSerializing(fieldExpressions[4]);
300+
301+
/** or we might even want to chain multiple `.AppendSuffix()` calls */
302+
var multiSuffixFieldExpressions =
303+
expressions.Select<Expression<Func<Project, object>>, Field>(e => e.AppendSuffix("raw").AppendSuffix("evendeeper")).ToList();
304+
305+
Expect("name.raw.evendeeper").WhenSerializing(multiSuffixFieldExpressions[0]);
306+
Expect("description.raw.evendeeper").WhenSerializing(multiSuffixFieldExpressions[1]);
307+
Expect("curatedTags.name.raw.evendeeper").WhenSerializing(multiSuffixFieldExpressions[2]);
308+
Expect("leadDeveloper.firstName.raw.evendeeper").WhenSerializing(multiSuffixFieldExpressions[3]);
309+
Expect("metadata.hardcoded.raw.evendeeper").WhenSerializing(multiSuffixFieldExpressions[4]);
298310
}
299311

300312
/**=== Attribute based naming

0 commit comments

Comments
 (0)