Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-45822 Add convention packs section #447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions source/fundamentals/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,55 @@ Implementing the `IBsonArraySerializer
interface enables the driver to access serialization information for individual
items in an array.

.. _csharp-conventions:

Conventions
-----------

Convention packs allow you to define and apply
**conventions** to your classes and their members that the driver uses during serialization.
Conventions specify how data is mapped between your
{+language+} objects and MongoDB documents without requiring you to decorate
each class with attributes.

The {+driver-short+} provides built-in conventions that you can use to
customize the serialization process. The following table describes some of the
built-in conventions:

.. list-table::
:header-rows: 1
:widths: 40 60

* - Convention
- Description

* - `CamelCaseElementNameConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.CamelCaseElementNameConvention.html>`__
- Converts element names to camel case during serialization and deserialization.

* - `EnumRepresentationConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.EnumRepresentationConvention.html>`__
- Converts enum values to a specified representation during serialization
and deserialization.

* - `IgnoreExtraElementsConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.IgnoreExtraElementsConvention.html>`__
- Specifies whether to ignore extra elements in a document during deserialization.

* - `ObjectSerializerAllowedTypesConvention <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ObjectSerializerAllowedTypesConvention.html>`__
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link will be broken until the API docs are released

- Specifies which types are allowed to be serialized using an object
serializer.

To view a full list of available conventions, see the `Conventions
<{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.html>`__
class reference in the API Documentation.

You can register a convention by instantiating a ``ConventionPack`` with the
specified conventions, then passing it to the
``ConventionRegistry.Register()`` method, as shown in the following example:

.. code-block:: csharp

var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
ConventionRegistry.Register("CamelCaseConvention", camelCaseConvention, t => true);

Additional Information
----------------------

Expand All @@ -157,3 +206,6 @@ guide, see the following API documentation:
- `SerializerRegistry <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.SerializerRegistry.html>`__
- `BsonSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.BsonSerializer.html>`__
- `IBsonSerializer <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.IBsonSerializer.html>`__
- `ConventionPack <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ConventionPack.html>`__
- `ConventionRegistry <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.ConventionRegistry.html>`__
- `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__>`__
3 changes: 3 additions & 0 deletions source/fundamentals/serialization/poco.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ MongoDB collection.

var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() };
ConventionRegistry.Register("CamelCase", camelCaseConvention, type => true);

For more information about conventions, see the
:ref:`csharp-conventions` section of the Serialization guide.

Select Type Representation
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 13 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ What's New

Learn what's new in:

* :ref:`Version 3.2 <csharp-version-3.2>`
* :ref:`Version 3.1 <csharp-version-3.1>`
* :ref:`Version 3.0 <csharp-version-3.0>`
* :ref:`Version 2.30 <csharp-version-2.30>`
Expand All @@ -33,6 +34,18 @@ Learn what's new in:

.. _upcoming-breaking-changes:

.. _csharp-version-3.2:

What's New in 3.2
-----------------

The 3.2 driver release includes the following new features:

- Adds a new ``ObjectSerializerAllowedTypesConvention`` convention that
allows you to specify which types are allowed to be serialized and
deserialized by the object serializer. To learn more about conventions,
see the :ref:`csharp-conventions` guide.

.. _csharp-version-3.1:

What's New in 3.1
Expand Down
Loading