Skip to content

Commit 4a7ab56

Browse files
committed
Update docs
This commit fixes some spelling mistakes in documentation and updates some wording to make the documentation flow better
1 parent 37833e9 commit 4a7ab56

File tree

4 files changed

+97
-61
lines changed

4 files changed

+97
-61
lines changed

docs/client-concepts/high-level/inference/field-inference.asciidoc

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ but for expressions this is still rather involved
127127

128128
[source,csharp]
129129
----
130-
var fieldExpression = Infer.Field<Project>(p => p.Name);
130+
var fieldExpression = Field<Project>(p => p.Name);
131131
----
132132

133133
this can be even shortened even further using a static import.
@@ -172,15 +172,16 @@ var setup = WithConnectionSettings(s => s.DefaultFieldNameInferrer(p => p.ToUppe
172172
setup.Expect("NAME").WhenSerializing(Field<Project>(p => p.Name));
173173
----
174174

175-
However `string` types are *always* passed along verbatim
175+
A `Field` constructed from a `string` however is *always* passed along verbatim
176176

177177
[source,csharp]
178178
----
179179
setup.Expect("NaMe").WhenSerializing<Field>("NaMe");
180180
----
181181

182-
Of you want the same behavior for expressions, simply pass a Func<string,string> to `DefaultFieldNameInferrer`
183-
to make no changes to the name
182+
If you'd like NEST to not change the casing of field names at all,
183+
simply pass a Func<string,string> to `DefaultFieldNameInferrer` that simply returns the
184+
input string
184185

185186
[source,csharp]
186187
----
@@ -213,7 +214,7 @@ Expect("curatedTags.added").WhenSerializing(Field<Project>(p => p.CuratedTags[0]
213214
Expect("curatedTags.name").WhenSerializing(Field<Project>(p => p.CuratedTags.First().Name));
214215
----
215216

216-
NOTE: Remember, these are _expressions_ and not actual code that will be executed
217+
NOTE: Remember, these are _expressions_ to access members, and not actual code that will be executed
217218

218219
An indexer on a dictionary is assumed to describe a property name
219220

@@ -461,11 +462,15 @@ fieldNameOnB.Should().Be("c.name");
461462

462463
To wrap up, the precedence in which field names are inferred is:
463464

464-
1) A naming of the property on `ConnectionSettings` using `.PropertyName()`
465-
2) A NEST `PropertyNameAttribute`
466-
3) Ask the serializer if the property has a verbatim value, e.g. it has a `JsonPropertyAttribute` if using {nuget}/NEST.JsonNetSerializer[`JsonNetSerializer`]
467-
4) See if the `MemberInfo` has a `DataMemberAttribute` applied
468-
5) Pass the `MemberInfo` to the `DefaultFieldNameInferrer`, which by default will camel case the `Name` property
465+
. A naming of the property on `ConnectionSettings` using `.PropertyName()`
466+
467+
. A NEST `PropertyNameAttribute`
468+
469+
. Ask the serializer if the property has a verbatim value, e.g. it has a `JsonPropertyAttribute` if using {nuget}/NEST.JsonNetSerializer[`JsonNetSerializer`]
470+
471+
. See if the `MemberInfo` has a `DataMemberAttribute` applied
472+
473+
. Pass the `MemberInfo` to the `DefaultFieldNameInferrer`, which by default will camel case the `Name` property
469474

470475
The following example class will demonstrate this precedence
471476

@@ -508,7 +513,8 @@ class Precedence
508513

509514
<6> We are going to register a DefaultFieldNameInferrer on ConnectionSettings that will uppercase all properties.
510515

511-
Here we create a custom serializer that renames any property named `AskSerializer` to `ask`
516+
We'll create a custom `IPropertyMappingProvider` that renames any property named `AskSerializer` to `ask`.
517+
and hook it up when creating the Connection Settings in the following section.
512518

513519
[source,csharp]
514520
----
@@ -523,18 +529,23 @@ class CustomPropertyMappingProvider : PropertyMappingProvider
523529
}
524530
----
525531

526-
Here we provide an explicit rename of a property on `ConnectionSettings` using `.PropertyName()`
527-
and all properties that are not mapped verbatim should be uppercased
532+
Now, when we create the Connection Settings to use to configure the client, we'll add
533+
534+
* a default mapping for the `Precedence` type
535+
536+
* our `CustomPropertyMappingProvider`
537+
538+
* a delegate to perform default field name inference
528539

529540
[source,csharp]
530541
----
531542
var usingSettings = WithConnectionSettings(s => s
532543
533544
.DefaultMappingFor<Precedence>(m => m
534-
.PropertyName(p => p.RenamedOnConnectionSettings, "renamed")
545+
.PropertyName(p => p.RenamedOnConnectionSettings, "renamed") <1>
535546
)
536-
.DefaultFieldNameInferrer(p => p.ToUpperInvariant())
537-
).WithPropertyMappingProvider(new CustomPropertyMappingProvider());
547+
.DefaultFieldNameInferrer(p => p.ToUpperInvariant()) <2>
548+
).WithPropertyMappingProvider(new CustomPropertyMappingProvider()); <3>
538549
539550
usingSettings.Expect("renamed").ForField(Field<Precedence>(p => p.RenamedOnConnectionSettings));
540551
usingSettings.Expect("nestAtt").ForField(Field<Precedence>(p => p.NestAttribute));
@@ -544,6 +555,11 @@ usingSettings.Expect("ask").ForField(Field<Precedence>(p => p.AskSerializer));
544555
usingSettings.Expect("data").ForField(Field<Precedence>(p => p.DataMember));
545556
usingSettings.Expect("DEFAULTFIELDNAMEINFERRER").ForField(Field<Precedence>(p => p.DefaultFieldNameInferrer));
546557
----
558+
<1> Rename on the mapping for the `Precedence` type
559+
560+
<2> Default inference for a field, if no other rules apply or are specified for a given field
561+
562+
<3> Hook up the custom `IPropertyMappingProvider`
547563

548564
The same naming rules also apply when indexing a document
549565

@@ -568,36 +584,43 @@ usingSettings.Expect(new []
568584
DefaultFieldNameInferrer = "shouting much?",
569585
DataMember = "using a DataMember attribute"
570586
});
587+
----
571588

572-
public class Parent
573-
{
574-
public int Id { get; set; }
575-
public string Description { get; set; }
576-
public string IgnoreMe { get; set; }
577-
}
589+
[[inherited-field-inference]]
590+
==== Overriding inherited field inference
578591

579-
public class Child : Parent { }
580-
----
592+
Properties inherited from a base type can be ignored and renamed using `DefaultMappingFor<T>` for
593+
a given type, on Connection Settings.
581594

582-
Inherited properties can be ignored and renamed just as one would expect
595+
To demonstrate, the `IgnoreMe` property on `Parent` can be ignored on the `Child` type, and the
596+
`Description` property renamed, using `DefaultMappingFor<Child>(...)`
583597

584598
[source,csharp]
585599
----
600+
public class Parent
601+
{
602+
public int Id { get; set; }
603+
public string Description { get; set; }
604+
public string IgnoreMe { get; set; }
605+
}
606+
607+
public class Child : Parent { }
608+
586609
var usingSettings = WithConnectionSettings(s => s
587-
.DefaultMappingFor<Child>(m => m
588-
.PropertyName(p => p.Description, "desc")
589-
.Ignore(p => p.IgnoreMe)
590-
)
591-
);
610+
.DefaultMappingFor<Child>(m => m
611+
.PropertyName(p => p.Description, "desc")
612+
.Ignore(p => p.IgnoreMe)
613+
)
614+
);
592615
usingSettings.Expect(new []
593-
{
594-
"id",
595-
"desc",
596-
}).AsPropertiesOf(new Child
597-
{
598-
Id = 1,
599-
Description = "using a nest attribute",
600-
IgnoreMe = "the default serializer resolves json property attributes",
601-
});
616+
{
617+
"id",
618+
"desc",
619+
}).AsPropertiesOf(new Child
620+
{
621+
Id = 1,
622+
Description = "this property will be renamed for Child",
623+
IgnoreMe = "this property will be ignored (won't be serialized) for Child",
624+
});
602625
----
603626

docs/common-options/union/union.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var sourceFilterInterface = new Union<bool, ISourceFilter>(new SourceFilter
6363
==== Match
6464

6565
The `Match` method can be used to operate on the value encapsulated by the instance of `Union<TFirst,TSecond>`.
66-
Two delegates are passed; one to operate on a `TFirst` value and the other toe operate on a `TSecond` value.
66+
Two delegates are passed; one to operate on a `TFirst` value and the other to operate on a `TSecond` value.
6767

6868
[source,csharp]
6969
----

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void UsingStaticPropertyField()
137137
Field fieldString = "name";
138138

139139
/** but for expressions this is still rather involved */
140-
var fieldExpression = Infer.Field<Project>(p => p.Name);
140+
var fieldExpression = Field<Project>(p => p.Name);
141141

142142
/** this can be even shortened even further using a static import.
143143
* Now that is much terser then our first example using the constructor!
@@ -174,12 +174,13 @@ public void DefaultFieldNameInferrer()
174174

175175
setup.Expect("NAME").WhenSerializing(Field<Project>(p => p.Name));
176176

177-
/** However `string` types are *always* passed along verbatim */
177+
/** A `Field` constructed from a `string` however is *always* passed along verbatim */
178178
setup.Expect("NaMe").WhenSerializing<Field>("NaMe");
179179

180-
/** Of you want the same behavior for expressions, simply pass a Func<string,string> to `DefaultFieldNameInferrer`
181-
* to make no changes to the name
182-
*/
180+
/** If you'd like NEST to not change the casing of field names at all,
181+
* simply pass a Func<string,string> to `DefaultFieldNameInferrer` that simply returns the
182+
* input string
183+
*/
183184
setup = WithConnectionSettings(s => s.DefaultFieldNameInferrer(p => p));
184185
setup.Expect("Name").WhenSerializing(Field<Project>(p => p.Name));
185186
}
@@ -200,7 +201,7 @@ public void ComplexFieldNameExpressions()
200201
Expect("curatedTags.added").WhenSerializing(Field<Project>(p => p.CuratedTags[0].Added));
201202
Expect("curatedTags.name").WhenSerializing(Field<Project>(p => p.CuratedTags.First().Name));
202203

203-
/** NOTE: Remember, these are _expressions_ and not actual code that will be executed
204+
/** NOTE: Remember, these are _expressions_ to access members, and not actual code that will be executed
204205
*
205206
* An indexer on a dictionary is assumed to describe a property name */
206207
Expect("metadata.hardcoded").WhenSerializing(Field<Project>(p => p.Metadata["hardcoded"]));
@@ -423,11 +424,11 @@ public void ExpressionsAreCachedButSeeDifferentTypes()
423424
* ==== Inference Precedence
424425
* To wrap up, the precedence in which field names are inferred is:
425426
*
426-
* 1) A naming of the property on `ConnectionSettings` using `.PropertyName()`
427-
* 2) A NEST `PropertyNameAttribute`
428-
* 3) Ask the serializer if the property has a verbatim value, e.g. it has a `JsonPropertyAttribute` if using {nuget}/NEST.JsonNetSerializer[`JsonNetSerializer`]
429-
* 4) See if the `MemberInfo` has a `DataMemberAttribute` applied
430-
* 5) Pass the `MemberInfo` to the `DefaultFieldNameInferrer`, which by default will camel case the `Name` property
427+
* . A naming of the property on `ConnectionSettings` using `.PropertyName()`
428+
* . A NEST `PropertyNameAttribute`
429+
* . Ask the serializer if the property has a verbatim value, e.g. it has a `JsonPropertyAttribute` if using {nuget}/NEST.JsonNetSerializer[`JsonNetSerializer`]
430+
* . See if the `MemberInfo` has a `DataMemberAttribute` applied
431+
* . Pass the `MemberInfo` to the `DefaultFieldNameInferrer`, which by default will camel case the `Name` property
431432
*
432433
* The following example class will demonstrate this precedence
433434
*/
@@ -457,7 +458,8 @@ class Precedence
457458
}
458459

459460
/**
460-
* Here we create a custom serializer that renames any property named `AskSerializer` to `ask`
461+
* We'll create a custom `IPropertyMappingProvider` that renames any property named `AskSerializer` to `ask`.
462+
* and hook it up when creating the Connection Settings in the following section.
461463
*/
462464
class CustomPropertyMappingProvider : PropertyMappingProvider
463465
{
@@ -473,16 +475,18 @@ public override IPropertyMapping CreatePropertyMapping(MemberInfo memberInfo)
473475
[ProjectReferenceOnly]
474476
public void PrecedenceIsAsExpected()
475477
{
476-
/** Here we provide an explicit rename of a property on `ConnectionSettings` using `.PropertyName()`
477-
* and all properties that are not mapped verbatim should be uppercased
478+
/** Now, when we create the Connection Settings to use to configure the client, we'll add
479+
* - a default mapping for the `Precedence` type
480+
* - our `CustomPropertyMappingProvider`
481+
* - a delegate to perform default field name inference
478482
*/
479483
var usingSettings = WithConnectionSettings(s => s
480484

481485
.DefaultMappingFor<Precedence>(m => m
482-
.PropertyName(p => p.RenamedOnConnectionSettings, "renamed")
486+
.PropertyName(p => p.RenamedOnConnectionSettings, "renamed") // <1> Rename on the mapping for the `Precedence` type
483487
)
484-
.DefaultFieldNameInferrer(p => p.ToUpperInvariant())
485-
).WithPropertyMappingProvider(new CustomPropertyMappingProvider());
488+
.DefaultFieldNameInferrer(p => p.ToUpperInvariant()) // <2> Default inference for a field, if no other rules apply or are specified for a given field
489+
).WithPropertyMappingProvider(new CustomPropertyMappingProvider()); // <3> Hook up the custom `IPropertyMappingProvider`
486490

487491
usingSettings.Expect("renamed").ForField(Field<Precedence>(p => p.RenamedOnConnectionSettings));
488492
usingSettings.Expect("nestAtt").ForField(Field<Precedence>(p => p.NestAttribute));
@@ -515,6 +519,16 @@ public void PrecedenceIsAsExpected()
515519
});
516520
}
517521

522+
/**
523+
*[[inherited-field-inference]]
524+
* ==== Overriding inherited field inference
525+
*
526+
* Properties inherited from a base type can be ignored and renamed using `DefaultMappingFor<T>` for
527+
* a given type, on Connection Settings.
528+
*
529+
* To demonstrate, the `IgnoreMe` property on `Parent` can be ignored on the `Child` type, and the
530+
* `Description` property renamed, using `DefaultMappingFor<Child>(...)`
531+
*/
518532
public class Parent
519533
{
520534
public int Id { get; set; }
@@ -527,7 +541,6 @@ public class Child : Parent { }
527541
[U]
528542
public void CodeBasedConfigurationInherits()
529543
{
530-
/** Inherited properties can be ignored and renamed just as one would expect */
531544
var usingSettings = WithConnectionSettings(s => s
532545
.DefaultMappingFor<Child>(m => m
533546
.PropertyName(p => p.Description, "desc")
@@ -541,8 +554,8 @@ public void CodeBasedConfigurationInherits()
541554
}).AsPropertiesOf(new Child
542555
{
543556
Id = 1,
544-
Description = "using a nest attribute",
545-
IgnoreMe = "the default serializer resolves json property attributes",
557+
Description = "this property will be renamed for Child",
558+
IgnoreMe = "this property will be ignored (won't be serialized) for Child",
546559
});
547560

548561
}

src/Tests/CommonOptions/Union/Union.doc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void Constructor()
6969
* ==== Match
7070
*
7171
* The `Match` method can be used to operate on the value encapsulated by the instance of `Union<TFirst,TSecond>`.
72-
* Two delegates are passed; one to operate on a `TFirst` value and the other toe operate on a `TSecond` value.
72+
* Two delegates are passed; one to operate on a `TFirst` value and the other to operate on a `TSecond` value.
7373
*/
7474
sourceFilterTrue.Match(
7575
b => b.Should().BeTrue(),

0 commit comments

Comments
 (0)