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 2 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
51 changes: 51 additions & 0 deletions source/fundamentals/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,54 @@ Implementing the `IBsonArraySerializer
interface enables the driver to access serialization information for individual
items in an array.

.. _csharp-convention-packs:

Convention Packs
----------------

Convention packs allow you to define and apply
**conventions** to your classes and their members during serialization.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"during serialization"

Technically conventions are applied before serialization while auto configuring class maps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the wording here. It was meant to convey that the conventions you specify are used/followed in the serialization process

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 convention packs that you can use to
customize the serialization process. The following table describes some of the
built-in convention packs:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The following are conventions, not convention-packs.

Convention-packs are sets of conventions that have been bundled to be used together.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the clarification. Updated the section to refer to conventions rather than convention packs in most instances


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

* - Convention Pack
- 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 convention packs, see the `Conventions
<{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.Serialization.Conventions.html>`__
class reference in the API Documentation.

You can register a convention pack by passing an instance of the pack 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 +205,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 convention packs, see the
:ref:`csharp-convention-packs` 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 pack that
Copy link
Collaborator

Choose a reason for hiding this comment

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

ObjectSerializerAllowedTypesConvention is a convention, not a convention pack.

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

.. _csharp-version-3.1:

What's New in 3.1
Expand Down
Loading