@@ -140,6 +140,55 @@ Implementing the `IBsonArraySerializer
140
140
interface enables the driver to access serialization information for individual
141
141
items in an array.
142
142
143
+ .. _csharp-conventions:
144
+
145
+ Conventions
146
+ -----------
147
+
148
+ Convention packs allow you to define and apply
149
+ **conventions** to your classes and their members that the driver uses during serialization.
150
+ Conventions specify how data is mapped between your
151
+ {+language+} objects and MongoDB documents without requiring you to decorate
152
+ each class with attributes.
153
+
154
+ The {+driver-short+} provides built-in conventions that you can use to
155
+ customize the serialization process. The following table describes some of the
156
+ built-in conventions:
157
+
158
+ .. list-table::
159
+ :header-rows: 1
160
+ :widths: 40 60
161
+
162
+ * - Convention
163
+ - Description
164
+
165
+ * - `CamelCaseElementNameConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.CamelCaseElementNameConvention.html>`__
166
+ - Converts element names to camel case during serialization and deserialization.
167
+
168
+ * - `EnumRepresentationConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.EnumRepresentationConvention.html>`__
169
+ - Converts enum values to a specified representation during serialization
170
+ and deserialization.
171
+
172
+ * - `IgnoreExtraElementsConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.IgnoreExtraElementsConvention.html>`__
173
+ - Specifies whether to ignore extra elements in a document during deserialization.
174
+
175
+ * - `ObjectSerializerAllowedTypesConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ObjectSerializerAllowedTypesConvention.html>`__
176
+ - Specifies which types are allowed to be serialized using an object
177
+ serializer.
178
+
179
+ To view a full list of available conventions, see the `Conventions
180
+ <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.html>`__
181
+ class reference in the API Documentation.
182
+
183
+ You can register a convention by instantiating a ``ConventionPack`` with the
184
+ specified conventions, then passing it to the
185
+ ``ConventionRegistry.Register()`` method, as shown in the following example:
186
+
187
+ .. code-block:: csharp
188
+
189
+ var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
190
+ ConventionRegistry.Register("CamelCaseConvention", camelCaseConvention, t => true);
191
+
143
192
Additional Information
144
193
----------------------
145
194
@@ -157,3 +206,6 @@ guide, see the following API documentation:
157
206
- `SerializerRegistry <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.SerializerRegistry.html>`__
158
207
- `BsonSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.html>`__
159
208
- `IBsonSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.IBsonSerializer.html>`__
209
+ - `ConventionPack <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ConventionPack.html>`__
210
+ - `ConventionRegistry <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ConventionRegistry.html>`__
211
+ - `Register() <{+new-api-root+}/MongoDB.Bson.Serialization.Conventions.ConventionRegistry.Register.html#MongoDB_Bson_Serialization_Conventions_ConventionRegistry_Register_System_String_MongoDB_Bson_Serialization_Conventions_IConventionPack_System_Func_System_Type_System_Boolean__>`__
0 commit comments