Skip to content
Browse files

Incorporated Brian Knight's fix for CSHARP-310 with minor changes.

  • Loading branch information...
1 parent af4da34 commit bb88a48b016227d9bebc7b8c5f966122bcb700f1 rstam committed Oct 17, 2011
Showing with 10 additions and 12 deletions.
  1. +1 −1 Bson/Serialization/BsonClassMap.cs
  2. +5 −4 Bson/Serialization/BsonMemberMap.cs
  3. +4 −7 BsonUnitTests/Jira/CSharp310Tests.cs
View
2 Bson/Serialization/BsonClassMap.cs
@@ -878,7 +878,7 @@ MemberInfo memberInfo
var defaultValue = conventions.DefaultValueConvention.GetDefaultValue(memberInfo);
if (defaultValue != null) {
- memberMap.SetDefaultValue(defaultValue, memberMap.SerializeDefaultValue);
+ memberMap.SetDefaultValue(defaultValue);
}
// see if the class has a method called ShouldSerializeXyz where Xyz is the name of this member
View
9 Bson/Serialization/BsonMemberMap.cs
@@ -242,7 +242,9 @@ Type actualType
public BsonMemberMap SetDefaultValue(
object defaultValue
) {
- return SetDefaultValue(defaultValue, true); // serializeDefaultValue
+ this.defaultValue = defaultValue;
+ this.hasDefaultValue = true;
+ return this;
}
/// <summary>
@@ -255,9 +257,8 @@ object defaultValue
object defaultValue,
bool serializeDefaultValue
) {
- this.hasDefaultValue = true;
- this.serializeDefaultValue = serializeDefaultValue;
- this.defaultValue = defaultValue;
+ SetDefaultValue(defaultValue);
+ SetSerializeDefaultValue(serializeDefaultValue);
return this;
}
View
11 BsonUnitTests/Jira/CSharp310Tests.cs
@@ -24,23 +24,20 @@
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
-
namespace MongoDB.BsonUnitTests.Jira {
[TestFixture]
public class CSharp310Tests {
private class C {
public int Id;
- public Guid G;
+ public Guid G = Guid.Empty;
}
private class EmptyGuidDefaultValueConvention : IDefaultValueConvention {
public object GetDefaultValue(MemberInfo memberInfo) {
- var type = (memberInfo.MemberType == MemberTypes.Field)
- ? ((FieldInfo)memberInfo).FieldType : ((PropertyInfo)memberInfo).PropertyType;
+ var type = (memberInfo.MemberType == MemberTypes.Field) ? ((FieldInfo) memberInfo).FieldType : ((PropertyInfo) memberInfo).PropertyType;
if (type == typeof(Guid)) {
return Guid.Empty;
- }
- else {
+ } else {
return null;
}
}
@@ -67,4 +64,4 @@ private class EmptyGuidDefaultValueConvention : IDefaultValueConvention {
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson<object>()));
}
}
-}
+}

0 comments on commit bb88a48

Please sign in to comment.
Something went wrong with that request. Please try again.