@@ -31,7 +31,7 @@ the name of the field in the document to the name of the property in the class.
3131 The type of the property in your class should match the type of the field in
3232 the document. The {+driver-short+} instantiates a serializer based on the
3333 type of the property in your class. If the types don't match when the driver
34- attempts to serialize the data, the serializer will throw an exception.
34+ attempts to deserialize the data, the serializer throws an exception.
3535
3636Manually Creating A Class Map
3737-----------------------------
@@ -55,11 +55,11 @@ class:
5555
5656.. code-block:: csharp
5757
58- BsonClassMap.RegisterClassMap<Person>(classmap =>
58+ BsonClassMap.RegisterClassMap<Person>(classMap =>
5959 {
60- classmap .MapMember(p => p.Name);
61- classmap .MapMember(p => p.Age);
62- classmap .MapMember(p => p.Hobbies);
60+ classMap .MapMember(p => p.Name);
61+ classMap .MapMember(p => p.Age);
62+ classMap .MapMember(p => p.Hobbies);
6363 });
6464
6565.. important::
@@ -73,14 +73,15 @@ register a class map and call the ``AutoMap()`` method before manually
7373specifying your properties.
7474
7575In the following code example, the ``AutoMap()`` method maps all properties
76- of the ``Person`` class except ``Hobbies``, which is mapped manually:
76+ of the ``Person`` class, then manually adjusts the mapping for the ``Hobbies``
77+ field:
7778
7879.. code-block:: csharp
7980
80- BsonClassMap.RegisterClassMap<Person>(classmap =>
81+ BsonClassMap.RegisterClassMap<Person>(classMap =>
8182 {
82- classmap .AutoMap();
83- classmap .MapMember(p => p.Hobbies);
83+ classMap .AutoMap();
84+ classMap .MapMember(p => p.Hobbies).SetElementName("favorite_hobbies" );
8485 });
8586
8687Customize Class Serialization
@@ -120,10 +121,10 @@ You can also ignore any extra elements when registering a class map:
120121
121122.. code-block:: csharp
122123
123- BsonClassMap.RegisterClassMap<Person>(classmap =>
124+ BsonClassMap.RegisterClassMap<Person>(classMap =>
124125 {
125- classmap .AutoMap();
126- classmap .SetIgnoreExtraElements(true);
126+ classMap .AutoMap();
127+ classMap .SetIgnoreExtraElements(true);
127128 });
128129
129130Using Class Discriminators
@@ -152,10 +153,10 @@ You can also specify a discriminator when registering a class map as follows:
152153
153154.. code-block:: csharp
154155
155- BsonClassMap.RegisterClassMap<Person>(classmap =>
156+ BsonClassMap.RegisterClassMap<Person>(classMap =>
156157 {
157- classmap .AutoMap();
158- classmap .SetDiscriminator("personClass");
158+ classMap .AutoMap();
159+ classMap .SetDiscriminator("personClass");
159160 });
160161
161162In BSON, discriminators have the field name ``_t``.
@@ -165,7 +166,7 @@ The following example shows how a document from the ``Person`` class with the
165166
166167.. code-block:: json
167168
168- { "_id": "...", "_t": "personClass", "name ": "...", "age ": "...", "hobbies ": [...]}
169+ { "_id": "...", "_t": "personClass", "Name ": "...", "Age ": "...", "Hobbies ": [...]}
169170
170171.. TODO: Link to page on polymorphism/discriminators
171172
@@ -175,7 +176,7 @@ Mapping with Constructors
175176By default, the {+driver-short+} can automatically map a class only if the class has
176177a constructor with no arguments. If you want the driver to use a constructor that accepts
177178one or more arguments, you can add the ``BsonConstructor`` attribute to the constructor.
178- In this case, the driver parses the expression tree to determine how to map the
179+ In this case, the driver the driver examines the types to determine how to map the
179180constructor arguments to class properties or fields.
180181
181182When the driver creates a class map for the following ``Person`` class, it will use the
@@ -223,10 +224,10 @@ You can also specify the constructor to use when registering your class map:
223224 }
224225 }
225226
226- BsonClassMap.RegisterClassMap<Person>(classmap =>
227+ BsonClassMap.RegisterClassMap<Person>(classMap =>
227228 {
228- classmap .AutoMap();
229- classmap .MapCreator(p => new Person(p.Name, p.Age));
229+ classMap .AutoMap();
230+ classMap .MapCreator(p => new Person(p.Name, p.Age));
230231 });
231232
232233Customize Property Serialization
@@ -261,10 +262,10 @@ You can also support extra elements when initializing a class map as follows:
261262
262263.. code-block:: csharp
263264
264- BsonClassMap.RegisterClassMap<Person>(classmap =>
265+ BsonClassMap.RegisterClassMap<Person>(classMap =>
265266 {
266- classmap .AutoMap();
267- classmap .MapExtraElementsMember(p => p.ExtraElements);
267+ classMap .AutoMap();
268+ classMap .MapExtraElementsMember(p => p.ExtraElements);
268269 });
269270
270271.. note::
@@ -277,14 +278,15 @@ Dynamically Serialize Properties
277278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278279
279280You can use a method to determine whether or not to serialize a property. For
280- the driver to automatically use the method when serializing, the method must be
281- named ``ShouldSerialize<property name>``. When the driver sees a method with
282- this naming convention, it will use the method to determine whether or not to
283- serialize properties of the provided property name.
281+ the driver to automatically use the method when serializing, you must prefix the
282+ method name with ``ShouldSerialize`` followed by the name of the property that
283+ the method applies to. When the driver sees a method with this naming
284+ convention, it uses that method to determine whether or not to serialize
285+ properties that have the provided property name.
284286
285287The following example creates a method that only serializes the ``Age`` property
286- if its value is greater than ``0``. The driver ignores any properties whose
287- values don't meet this requirement:
288+ if its value is not equal to ``0``. The driver does not serialize any properties
289+ whose values don't meet this requirement:
288290
289291.. code-block:: csharp
290292
@@ -296,19 +298,19 @@ values don't meet this requirement:
296298
297299 public bool ShouldSerializeAge()
298300 {
299- return Age > 0;
301+ return Age != 0;
300302 }
301303 }
302304
303305You can also specify the method while registering a class map:
304306
305307.. code-block:: csharp
306308
307- BsonClassMap.RegisterClassMap<Employee>(classmap =>
309+ BsonClassMap.RegisterClassMap<Employee>(classMap =>
308310 {
309- classmap .AutoMap();
310- classmap .MapMember(p => c.Age).SetShouldSerializeMethod(
311- obj => ((Person) obj).Age > 0
311+ classMap .AutoMap();
312+ classMap .MapMember(p => c.Age).SetShouldSerializeMethod(
313+ obj => ((Person) obj).Age != 0
312314 );
313315 });
314316
0 commit comments