public BsonMemberMap( MemberInfo memberInfo, ConventionProfile conventions ) { this.memberInfo = memberInfo; this.memberType = BsonClassMap.GetMemberInfoType(memberInfo); this.conventions = conventions; }
public virtual void Init() { BsonClassMap.UnregisterClassMap(typeof(Exception)); var profile = new ConventionProfile(); profile.SetMemberFinderConvention(new LoggingMemberFinderConvention()); BsonClassMap.RegisterClassMap(new ExceptionMap()); BsonClassMap.RegisterClassMap(new LocationInformationMap()); BsonClassMap.RegisterConventions(profile, t => true); }
public void TestSave() { var server = MongoServer.Create(); var database = server["onlinetests"]; var collection = database.GetCollection<Foo>("csharp77"); var conventions = new ConventionProfile() .SetIdMemberConvention(new NamedIdMemberConvention("_id")); BsonClassMap.RegisterConventions(conventions, t => t == typeof(Foo)); collection.RemoveAll(); for (int i = 0; i < 10; i++) { var foo = new Foo { _id = ObjectId.Empty, Name = string.Format("Foo-{0}", i), Summary = string.Format("Summary for Foo-{0}", i) }; collection.Save(foo, SafeMode.True); var count = collection.Count(); Assert.AreEqual(i + 1, count); } }
public void Merge( ConventionProfile other ) { if (BsonIdGeneratorConvention == null) { BsonIdGeneratorConvention = other.BsonIdGeneratorConvention; } if (DefaultValueConvention == null) { DefaultValueConvention = other.DefaultValueConvention; } if (ElementNameConvention == null) { ElementNameConvention = other.ElementNameConvention; } if (IdMemberConvention == null) { IdMemberConvention = other.IdMemberConvention; } if (IgnoreExtraElementsConvention == null) { IgnoreExtraElementsConvention = other.IgnoreExtraElementsConvention; } if (IgnoreIfNullConvention == null) { IgnoreIfNullConvention = other.IgnoreIfNullConvention; } if(MemberFinderConvention == null) { MemberFinderConvention = other.MemberFinderConvention; } if (SerializeDefaultValueConvention == null) { SerializeDefaultValueConvention = other.SerializeDefaultValueConvention; } }