Skip to content

Commit 2ee7961

Browse files
DOCSP-45822 Add convention packs section (#447)
1 parent 9236b14 commit 2ee7961

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

source/fundamentals/serialization.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,55 @@ Implementing the `IBsonArraySerializer
140140
interface enables the driver to access serialization information for individual
141141
items in an array.
142142

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+
143192
Additional Information
144193
----------------------
145194

@@ -157,3 +206,6 @@ guide, see the following API documentation:
157206
- `SerializerRegistry <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.SerializerRegistry.html>`__
158207
- `BsonSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.html>`__
159208
- `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__>`__

source/fundamentals/serialization/poco.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ MongoDB collection.
168168

169169
var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
170170
ConventionRegistry.Register("CamelCase", camelCaseConvention, type => true);
171+
172+
For more information about conventions, see the
173+
:ref:`csharp-conventions` section of the Serialization guide.
171174

172175
Select Type Representation
173176
~~~~~~~~~~~~~~~~~~~~~~~~~~

source/whats-new.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ What's New
1919

2020
Learn what's new in:
2121

22+
* :ref:`Version 3.2 <csharp-version-3.2>`
2223
* :ref:`Version 3.1 <csharp-version-3.1>`
2324
* :ref:`Version 3.0 <csharp-version-3.0>`
2425
* :ref:`Version 2.30 <csharp-version-2.30>`
@@ -33,6 +34,18 @@ Learn what's new in:
3334

3435
.. _upcoming-breaking-changes:
3536

37+
.. _csharp-version-3.2:
38+
39+
What's New in 3.2
40+
-----------------
41+
42+
The 3.2 driver release includes the following new features:
43+
44+
- Adds a new ``ObjectSerializerAllowedTypesConvention`` convention that
45+
allows you to specify which types are allowed to be serialized and
46+
deserialized by the object serializer. To learn more about conventions,
47+
see the :ref:`csharp-conventions` guide.
48+
3649
.. _csharp-version-3.1:
3750

3851
What's New in 3.1

0 commit comments

Comments
 (0)