File tree Expand file tree Collapse file tree 2 files changed +35
-10
lines changed
BsonUnitTests/DefaultSerializer Expand file tree Collapse file tree 2 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -816,7 +816,17 @@ public BsonMemberMap MapProperty(string propertyName)
816
816
}
817
817
return MapMember ( propertyInfo ) ;
818
818
}
819
+ /// <summary>
820
+ /// Sets the creator for the object.
821
+ /// </summary>
822
+ /// <param name="creator">The creator.</param>
823
+ /// <returns>The class map (so method calls can be chained).</returns>
824
+ public BsonClassMap SetCreator ( Func < object > creator )
825
+ {
826
+ this . _creator = creator ;
827
+ return this ;
819
828
829
+ }
820
830
/// <summary>
821
831
/// Sets the discriminator.
822
832
/// </summary>
@@ -869,16 +879,6 @@ public void SetExtraElementsMember(BsonMemberMap memberMap)
869
879
_extraElementsMemberMap = memberMap ;
870
880
}
871
881
/// <summary>
872
- /// Sets the constructor for the object
873
- /// </summary>
874
- /// <param name="constructor"></param>
875
- public BsonClassMap SetConstructor ( Func < object > constructor )
876
- {
877
- this . _creator = constructor ;
878
- return this ;
879
-
880
- }
881
- /// <summary>
882
882
/// Adds a known type to the class map.
883
883
/// </summary>
884
884
/// <param name="type">The known type.</param>
Original file line number Diff line number Diff line change @@ -65,6 +65,16 @@ public A()
65
65
fieldMappedByAttribute2 = 10 ;
66
66
}
67
67
}
68
+
69
+ private class B
70
+ {
71
+ public int A { get ; set ; }
72
+
73
+ public B ( int a )
74
+ {
75
+ A = a ;
76
+ }
77
+ }
68
78
#pragma warning restore
69
79
70
80
[ Test ]
@@ -73,6 +83,21 @@ public void TestMappingPicksUpAllMembersWithAttributes()
73
83
var classMap = BsonClassMap . LookupClassMap ( typeof ( A ) ) ;
74
84
Assert . AreEqual ( 8 , classMap . AllMemberMaps . Count ( ) ) ;
75
85
}
86
+
87
+ [ Test ]
88
+ public void TestSetCreator ( )
89
+ {
90
+ var classMap = new BsonClassMap < B > ( cm =>
91
+ {
92
+ cm . AutoMap ( ) ;
93
+ cm . SetCreator ( ( ) => new B ( 10 ) ) ;
94
+ } ) ;
95
+
96
+ classMap . Freeze ( ) ;
97
+
98
+ var instance = ( B ) classMap . CreateInstance ( ) ;
99
+ Assert . AreEqual ( 10 , instance . A ) ;
100
+ }
76
101
}
77
102
78
103
[ TestFixture ]
You can’t perform that action at this time.
0 commit comments