@@ -17,8 +17,8 @@ please modify the original csharp file found at the link and submit the PR with
17
17
18
18
It is also possible to apply a transformation on all or specific properties.
19
19
20
- `.AutoMap()` internally implements the https://en.wikipedia.org/wiki/Visitor_pattern[visitor pattern].
21
- The default visitor, `NoopPropertyVisitor`, does nothing and acts as a blank canvas for you
20
+ `.AutoMap()` internally implements the https://en.wikipedia.org/wiki/Visitor_pattern[visitor pattern].
21
+ The default visitor, `NoopPropertyVisitor`, does nothing and acts as a blank canvas for you
22
22
to implement your own visiting methods.
23
23
24
24
For instance, let's create a custom visitor that disables doc values for numeric and boolean types
@@ -133,7 +133,7 @@ var expected = new
133
133
==== Visiting on PropertyInfo
134
134
135
135
You can even take the visitor approach a step further, and instead of visiting on `IProperty` types, visit
136
- directly on your POCO reflected `PropertyInfo` properties.
136
+ directly on your POCO reflected `PropertyInfo` properties.
137
137
138
138
As an example, let's create a visitor that maps all CLR types to an Elasticsearch text datatype `ITextProperty`).
139
139
@@ -183,3 +183,43 @@ var descriptor = new CreateIndexDescriptor("myindex")
183
183
}
184
184
----
185
185
186
+ ==== Skip properties
187
+
188
+ Through implementing `SkipProperty` on the visitor you can prevent certain properties from being mapped
189
+
190
+ [source,csharp]
191
+ ----
192
+ public class DictionaryDocument : SortedDictionary<string, dynamic>
193
+ {
194
+ public int Id { get; set; }
195
+ }
196
+
197
+ public class IgnoreInheritedPropertiesVisitor<T> : NoopPropertyVisitor
198
+ {
199
+ public override bool SkipProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
200
+ {
201
+ return propertyInfo?.DeclaringType != typeof(T);
202
+ }
203
+ }
204
+
205
+ var descriptor = new CreateIndexDescriptor("myindex")
206
+ .Mappings(ms => ms
207
+ .Map<DictionaryDocument>(m => m.AutoMap(new IgnoreInheritedPropertiesVisitor<DictionaryDocument>()))
208
+ );
209
+ ----
210
+
211
+ [source,javascript]
212
+ ----
213
+ {
214
+ "mappings": {
215
+ "dictionarydocument": {
216
+ "properties": {
217
+ "id": {
218
+ "type": "integer"
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ ----
225
+
0 commit comments