Skip to content

Commit ef7eece

Browse files
committed
Support Fluent and Initializer examples that do not use Expression body syntax
1 parent 3420eaa commit ef7eece

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

docs/asciidoc/Aggregations/WritingAggregations.doc.asciidoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,22 @@ An advanced scenario may involve an existing collection of aggregation functions
6060
on the request. Using LINQ's `.Aggregate()` method, each function can be applied to the aggregation descriptor
6161
(`childAggs` below) in turn, returning the descriptor after each function application.
6262

63+
[source, csharp]
64+
----
65+
{
66+
var aggregations = new List<Func<AggregationContainerDescriptor<CommitActivity>, IAggregationContainer>>
67+
{
68+
a => a.Average("average_per_child", avg => avg.Field(p => p.ConfidenceFactor)),
69+
a => a.Max("max_per_child", avg => avg.Field(p => p.ConfidenceFactor))
70+
};
71+
72+
return s => s
73+
.Aggregations(aggs => aggs
74+
.Children<CommitActivity>("name_of_child_agg", child => child
75+
.Aggregations(childAggs =>
76+
aggregations.Aggregate(childAggs, (acc, agg) => { agg(acc); return acc; })
77+
)
78+
)
79+
);
80+
}
81+
----

docs/asciidoc/ClientConcepts/HighLevel/Mapping/AutoMap.doc.asciidoc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ var descriptor = new CreateIndexDescriptor("myindex")
9999
);
100100
----
101101
Observe that NEST has inferred the Elasticsearch types based on the CLR type of our POCO properties.
102-
In this example, Birthday was mapped as a date, IsManager as a boolean, Salary as an integer, Employees
103-
as an object, and the remaining string properties as strings.
102+
In this example, Birthday was mapped as a date, hours as a long (ticks), IsManager as a boolean,
103+
Salary as an integer, Employees as an object, and the remaining string properties as strings.
104104

105105
[source, csharp]
106106
----
@@ -129,6 +129,10 @@ firstName = new
129129
{
130130
type = "string"
131131
},
132+
hours = new
133+
{
134+
type = "long"
135+
},
132136
isManager = new
133137
{
134138
type = "boolean"
@@ -167,6 +171,10 @@ properties = new
167171
{
168172
type = "string"
169173
},
174+
hours = new
175+
{
176+
type = "long"
177+
},
170178
isManager = new
171179
{
172180
type = "boolean"
@@ -276,6 +284,10 @@ var expected = new
276284
{
277285
type = "string"
278286
},
287+
hours = new
288+
{
289+
type = "long"
290+
},
279291
isManager = new
280292
{
281293
type = "boolean"
@@ -329,6 +341,10 @@ var expected = new
329341
{
330342
type = "string"
331343
},
344+
hours = new
345+
{
346+
type = "long"
347+
},
332348
isManager = new
333349
{
334350
type = "boolean"
@@ -472,6 +488,10 @@ var expected = new
472488
{
473489
type = "string"
474490
},
491+
hours = new
492+
{
493+
type = "long"
494+
},
475495
isManager = new
476496
{
477497
type = "boolean"

src/CodeGeneration/Nest.Litterateur/Walkers/DocumentationFileWalker.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node
5555
this.Blocks.AddRange(walker.Blocks);
5656
}
5757

58+
public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
59+
{
60+
if (!this.InsideFluentOrInitializerExample) return;
61+
var syntaxNode = node?.ChildNodes()?.LastOrDefault()?.WithAdditionalAnnotations();
62+
if (syntaxNode == null) return;
63+
var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line;
64+
var walker = new CodeWithDocumentationWalker(ClassDepth, line);
65+
walker.Visit(syntaxNode);
66+
this.Blocks.AddRange(walker.Blocks);
67+
}
68+
5869
public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
5970
{
6071
if (this.ClassDepth == 1) this.InsideAutoIncludeMethodBlock = true;

src/Tests/ClientConcepts/HighLevel/Mapping/AutoMap.doc.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Employee
3838
public DateTime Birthday { get; set; }
3939
public bool IsManager { get; set; }
4040
public List<Employee> Employees { get; set; }
41+
public TimeSpan Hours { get; set;}
4142
}
4243

4344
[U]
@@ -132,8 +133,8 @@ public void UsingAutoMap()
132133

133134
/**
134135
* Observe that NEST has inferred the Elasticsearch types based on the CLR type of our POCO properties.
135-
* In this example, Birthday was mapped as a date, IsManager as a boolean, Salary as an integer, Employees
136-
* as an object, and the remaining string properties as strings.
136+
* In this example, Birthday was mapped as a date, hours as a long (ticks), IsManager as a boolean,
137+
* Salary as an integer, Employees as an object, and the remaining string properties as strings.
137138
*/
138139
var expected = new
139140
{
@@ -160,6 +161,10 @@ public void UsingAutoMap()
160161
{
161162
type = "string"
162163
},
164+
hours = new
165+
{
166+
type = "long"
167+
},
163168
isManager = new
164169
{
165170
type = "boolean"
@@ -197,6 +202,10 @@ public void UsingAutoMap()
197202
firstName = new
198203
{
199204
type = "string"
205+
},
206+
hours = new
207+
{
208+
type = "long"
200209
},
201210
isManager = new
202211
{
@@ -341,6 +350,10 @@ public void UsingAutoMapWithAttributes()
341350
firstName = new
342351
{
343352
type = "string"
353+
},
354+
hours = new
355+
{
356+
type = "long"
344357
},
345358
isManager = new
346359
{
@@ -394,6 +407,10 @@ public void UsingAutoMapWithAttributes()
394407
firstName = new
395408
{
396409
type = "string"
410+
},
411+
hours = new
412+
{
413+
type = "long"
397414
},
398415
isManager = new
399416
{
@@ -542,6 +559,10 @@ public void OverridingAutoMappedAttributes()
542559
firstName = new
543560
{
544561
type = "string"
562+
},
563+
hours = new
564+
{
565+
type = "long"
545566
},
546567
isManager = new
547568
{

0 commit comments

Comments
 (0)