コード例 #1
0
 public BsonMemberMap(
     MemberInfo memberInfo,
     ConventionProfile conventions
 )
 {
     this.memberInfo = memberInfo;
     this.memberType = BsonClassMap.GetMemberInfoType(memberInfo);
     this.conventions = conventions;
 }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 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;
     }
 }