当前位置: 首页>>代码示例>>C#>>正文


C# BsonClassMap.AutoMap方法代码示例

本文整理汇总了C#中BsonClassMap.AutoMap方法的典型用法代码示例。如果您正苦于以下问题:C# BsonClassMap.AutoMap方法的具体用法?C# BsonClassMap.AutoMap怎么用?C# BsonClassMap.AutoMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonClassMap的用法示例。


在下文中一共展示了BsonClassMap.AutoMap方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MongoTest

 static MongoTest()
 {
     BsonSerializer.RegisterIdGenerator(typeof(string), StringObjectIdGenerator.Instance);
     var map = new BsonClassMap<Person>();
     map.AutoMap();
     BsonClassMap.RegisterClassMap(map);
 }
开发者ID:pvasek,项目名称:RavenVsMongo,代码行数:7,代码来源:MongoTest.cs

示例2: RegisterClassIgnoreExtraFields

 public void RegisterClassIgnoreExtraFields(Type type)
 {
     BsonClassMap cm = new BsonClassMap(type);
     cm.AutoMap();
     //cm.SetIgnoreExtraElements(true); // Let's see if this is the default
     BsonClassMap.RegisterClassMap(cm);
     //BsonSerializer.RegisterDiscriminatorConvention(type, new ScalarDiscriminatorConvention("type"));
 }
开发者ID:ermshiperete,项目名称:LfMerge,代码行数:8,代码来源:MongoRegistrar.cs

示例3: TestConventionProfileStillUsesDefaults

        public void TestConventionProfileStillUsesDefaults()
        {
            var classMap = new BsonClassMap<A>();
            classMap.AutoMap();

            var memberMap = classMap.GetMemberMap(x => x.S);

            Assert.IsNotNull(memberMap);
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:9,代码来源:CSharp728Tests.cs

示例4: RegisterClassWithDiscriminator

 public void RegisterClassWithDiscriminator(Type type)
 {
     string name = _mapper.GetFieldName(type);
     BsonClassMap cm = new BsonClassMap(type);
     cm.AutoMap();
     cm.SetDiscriminator(name);
     ExtraRegistrationSteps(type, cm); // Derived classes can implement this if they need to.
     BsonClassMap.RegisterClassMap(cm);
     // Don't need to RegisterDiscriminatorConvention for each subclass, only for the base class.
     //BsonSerializer.RegisterDiscriminatorConvention(type, new ScalarDiscriminatorConvention("type"));
 }
开发者ID:ermshiperete,项目名称:LfMerge,代码行数:11,代码来源:MongoRegistrar.cs

示例5: TestConventionProfileStillUsesDefaults

        public void TestConventionProfileStillUsesDefaults()
        {
#pragma warning disable 618 
            var conventions = new ConventionProfile();
            conventions.SetElementNameConvention(new CamelCaseElementNameConvention());
            BsonClassMap.RegisterConventions(conventions, t => t == typeof(A));
#pragma warning restore 618
            var classMap = new BsonClassMap<A>();
            classMap.AutoMap();

            var memberMap = classMap.GetMemberMap(x => x.S);

            Assert.IsNotNull(memberMap);
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:14,代码来源:CSharp728Tests.cs

示例6: RegisterClassMap

        public static bool RegisterClassMap(Type classType)
        {
            if (BsonClassMap.IsClassMapRegistered(classType))
                return false;

            var classMap = new BsonClassMap(classType);

            // start with auto map
            classMap.AutoMap();

            // ignore extra elements for smooth schema change
            classMap.SetIgnoreExtraElements(true);

            // unmap all members which has mongodb.ignore attribute
            var deletingMembers = classMap.DeclaredMemberMaps.Where(m =>
            {
                return TrackablePropertyAttribute.GetParameter(m.MemberInfo, "mongodb.ignore") != null;
            }).ToList();
            foreach (var m in deletingMembers)
                classMap.UnmapMember(m.MemberInfo);

            // set default ignore for saving spaces
            foreach (var memberMap in classMap.DeclaredMemberMaps)
            {
                var mt = memberMap.MemberType;
                var defaultValue = mt.IsValueType ? Activator.CreateInstance(mt) : null;
                memberMap.SetDefaultValue(defaultValue);
                memberMap.SetIgnoreIfDefault(true);
            }

            try
            {
                BsonClassMap.RegisterClassMap(classMap);
            }
            catch (ArgumentException)
            {
                // if duplicate key exists
                return false;
            }

            return true;
        }
开发者ID:cupsster,项目名称:TrackableData,代码行数:42,代码来源:TypeMapper.cs

示例7: ConfigureErrorStackClassMap

 protected static void ConfigureErrorStackClassMap(BsonClassMap<Stack> cm) {
     cm.AutoMap();
     cm.SetIgnoreExtraElements(true);
     cm.SetIdMember(cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator()));
     cm.GetMemberMap(p => p.OrganizationId).SetElementName(ErrorStackFieldNames.OrganizationId).SetRepresentation(BsonType.ObjectId);
     cm.GetMemberMap(c => c.ProjectId).SetRepresentation(BsonType.ObjectId).SetElementName(ErrorStackFieldNames.ProjectId);
     cm.GetMemberMap(c => c.SignatureHash).SetElementName(ErrorStackFieldNames.SignatureHash);
     cm.GetMemberMap(c => c.SignatureInfo).SetElementName(ErrorStackFieldNames.SignatureInfo);
     cm.GetMemberMap(c => c.FixedInVersion).SetElementName(ErrorStackFieldNames.FixedInVersion).SetIgnoreIfNull(true);
     cm.GetMemberMap(c => c.DateFixed).SetElementName(ErrorStackFieldNames.DateFixed).SetIgnoreIfNull(true);
     cm.GetMemberMap(c => c.Title).SetElementName(ErrorStackFieldNames.Title);
     cm.GetMemberMap(c => c.TotalOccurrences).SetElementName(ErrorStackFieldNames.TotalOccurrences);
     cm.GetMemberMap(c => c.FirstOccurrence).SetElementName(ErrorStackFieldNames.FirstOccurrence);
     cm.GetMemberMap(c => c.LastOccurrence).SetElementName(ErrorStackFieldNames.LastOccurrence);
     cm.GetMemberMap(c => c.Description).SetElementName(ErrorStackFieldNames.Description).SetIgnoreIfNull(true);
     cm.GetMemberMap(c => c.IsHidden).SetElementName(ErrorStackFieldNames.IsHidden).SetIgnoreIfDefault(true);
     cm.GetMemberMap(c => c.IsRegressed).SetElementName(ErrorStackFieldNames.IsRegressed).SetIgnoreIfDefault(true);
     cm.GetMemberMap(c => c.DisableNotifications).SetElementName(ErrorStackFieldNames.DisableNotifications).SetIgnoreIfDefault(true);
     cm.GetMemberMap(c => c.OccurrencesAreCritical).SetElementName(ErrorStackFieldNames.OccurrencesAreCritical).SetIgnoreIfDefault(true);
     cm.GetMemberMap(c => c.References).SetElementName(ErrorStackFieldNames.References).SetShouldSerializeMethod(obj => ((OldModels.ErrorStack)obj).References.Any());
     cm.GetMemberMap(c => c.Tags).SetElementName(ErrorStackFieldNames.Tags).SetShouldSerializeMethod(obj => ((OldModels.ErrorStack)obj).Tags.Any());
 }
开发者ID:hanu412,项目名称:Exceptionless,代码行数:22,代码来源:MigrationJobBase.cs

示例8: ConfigureErrorClassMap

        protected static void ConfigureErrorClassMap(BsonClassMap<OldModels.Error> cm) {
            cm.AutoMap();
            cm.SetIgnoreExtraElements(true);
            cm.SetIdMember(cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator()));
            cm.GetMemberMap(p => p.OrganizationId).SetElementName(ErrorFieldNames.OrganizationId).SetRepresentation(BsonType.ObjectId);
            cm.GetMemberMap(c => c.ErrorStackId).SetElementName(ErrorFieldNames.ErrorStackId).SetRepresentation(BsonType.ObjectId);
            cm.GetMemberMap(c => c.ProjectId).SetElementName(ErrorFieldNames.ProjectId).SetRepresentation(BsonType.ObjectId);
            cm.GetMemberMap(c => c.OccurrenceDate).SetElementName(ErrorFieldNames.OccurrenceDate).SetSerializer(new UtcDateTimeOffsetSerializer());
            cm.GetMemberMap(c => c.Tags).SetElementName(ErrorFieldNames.Tags).SetIgnoreIfNull(true).SetShouldSerializeMethod(obj => ((OldModels.Error)obj).Tags.Any());
            cm.GetMemberMap(c => c.UserEmail).SetElementName(ErrorFieldNames.UserEmail).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.UserName).SetElementName(ErrorFieldNames.UserName).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.UserDescription).SetElementName(ErrorFieldNames.UserDescription).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.RequestInfo).SetElementName(ErrorFieldNames.RequestInfo).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.ExceptionlessClientInfo).SetElementName(ErrorFieldNames.ExceptionlessClientInfo).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.Modules).SetElementName(ErrorFieldNames.Modules).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.EnvironmentInfo).SetElementName(ErrorFieldNames.EnvironmentInfo).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.IsFixed).SetElementName(ErrorFieldNames.IsFixed).SetIgnoreIfDefault(true);
            cm.GetMemberMap(c => c.IsHidden).SetElementName(ErrorFieldNames.IsHidden).SetIgnoreIfDefault(true);

            if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.ErrorInfo))) {
                BsonClassMap.RegisterClassMap<OldModels.ErrorInfo>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.Message).SetElementName(ErrorFieldNames.Message).SetIgnoreIfNull(true);
                    cmm.GetMemberMap(c => c.Type).SetElementName(ErrorFieldNames.Type);
                    cmm.GetMemberMap(c => c.Code).SetElementName(ErrorFieldNames.Code);
                    cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.ErrorInfo)obj).ExtendedData.Any());
                    cmm.GetMemberMap(c => c.Inner).SetElementName(ErrorFieldNames.Inner);
                    cmm.GetMemberMap(c => c.StackTrace).SetElementName(ErrorFieldNames.StackTrace).SetShouldSerializeMethod(obj => ((OldModels.ErrorInfo)obj).StackTrace.Any());
                    cmm.GetMemberMap(c => c.TargetMethod).SetElementName(ErrorFieldNames.TargetMethod).SetIgnoreIfNull(true);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.RequestInfo))) {
                BsonClassMap.RegisterClassMap<OldModels.RequestInfo>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.UserAgent).SetElementName(ErrorFieldNames.UserAgent);
                    cmm.GetMemberMap(c => c.HttpMethod).SetElementName(ErrorFieldNames.HttpMethod);
                    cmm.GetMemberMap(c => c.IsSecure).SetElementName(ErrorFieldNames.IsSecure);
                    cmm.GetMemberMap(c => c.Host).SetElementName(ErrorFieldNames.Host);
                    cmm.GetMemberMap(c => c.Port).SetElementName(ErrorFieldNames.Port);
                    cmm.GetMemberMap(c => c.Path).SetElementName(ErrorFieldNames.Path);
                    cmm.GetMemberMap(c => c.Referrer).SetElementName(ErrorFieldNames.Referrer).SetIgnoreIfNull(true);
                    cmm.GetMemberMap(c => c.ClientIpAddress).SetElementName(ErrorFieldNames.ClientIpAddress);
                    cmm.GetMemberMap(c => c.Cookies).SetElementName(ErrorFieldNames.Cookies).SetShouldSerializeMethod(obj => ((RequestInfo)obj).Cookies.Any());
                    cmm.GetMemberMap(c => c.PostData).SetElementName(ErrorFieldNames.PostData).SetShouldSerializeMethod(obj => ShouldSerializePostData(obj as RequestInfo));
                    cmm.GetMemberMap(c => c.QueryString).SetElementName(ErrorFieldNames.QueryString).SetShouldSerializeMethod(obj => ((OldModels.RequestInfo)obj).QueryString.Any());
                    cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.RequestInfo)obj).ExtendedData.Any());
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.ExceptionlessClientInfo))) {
                BsonClassMap.RegisterClassMap<OldModels.ExceptionlessClientInfo>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.Version).SetElementName(ErrorFieldNames.Version);
                    cmm.GetMemberMap(c => c.InstallIdentifier).SetElementName(ErrorFieldNames.InstallIdentifier);
                    cmm.GetMemberMap(c => c.InstallDate).SetElementName(ErrorFieldNames.InstallDate);
                    cmm.GetMemberMap(c => c.StartCount).SetElementName(ErrorFieldNames.StartCount);
                    cmm.GetMemberMap(c => c.SubmitCount).SetElementName(ErrorFieldNames.SubmitCount);
                    cmm.GetMemberMap(c => c.Platform).SetElementName(ErrorFieldNames.Platform);
                    cmm.GetMemberMap(c => c.SubmissionMethod).SetElementName(ErrorFieldNames.SubmissionMethod);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.EnvironmentInfo))) {
                BsonClassMap.RegisterClassMap<OldModels.EnvironmentInfo>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.ProcessorCount).SetElementName(ErrorFieldNames.ProcessorCount);
                    cmm.GetMemberMap(c => c.TotalPhysicalMemory).SetElementName(ErrorFieldNames.TotalPhysicalMemory);
                    cmm.GetMemberMap(c => c.AvailablePhysicalMemory).SetElementName(ErrorFieldNames.AvailablePhysicalMemory);
                    cmm.GetMemberMap(c => c.CommandLine).SetElementName(ErrorFieldNames.CommandLine);
                    cmm.GetMemberMap(c => c.ProcessName).SetElementName(ErrorFieldNames.ProcessName);
                    cmm.GetMemberMap(c => c.ProcessId).SetElementName(ErrorFieldNames.ProcessId);
                    cmm.GetMemberMap(c => c.ProcessMemorySize).SetElementName(ErrorFieldNames.ProcessMemorySize);
                    cmm.GetMemberMap(c => c.ThreadName).SetElementName(ErrorFieldNames.ThreadName).SetIgnoreIfNull(true);
                    cmm.GetMemberMap(c => c.ThreadId).SetElementName(ErrorFieldNames.ThreadId);
                    cmm.GetMemberMap(c => c.Architecture).SetElementName(ErrorFieldNames.Architecture);
                    cmm.GetMemberMap(c => c.OSName).SetElementName(ErrorFieldNames.OSName);
                    cmm.GetMemberMap(c => c.OSVersion).SetElementName(ErrorFieldNames.OSVersion);
                    cmm.GetMemberMap(c => c.MachineName).SetElementName(ErrorFieldNames.MachineName);
                    cmm.GetMemberMap(c => c.RuntimeVersion).SetElementName(ErrorFieldNames.RuntimeVersion);
                    cmm.GetMemberMap(c => c.IpAddress).SetElementName(ErrorFieldNames.IpAddress);
                    cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.EnvironmentInfo)obj).ExtendedData.Any());
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.Method))) {
                BsonClassMap.RegisterClassMap<OldModels.Method>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.DeclaringNamespace).SetElementName(ErrorFieldNames.DeclaringNamespace);
                    cmm.GetMemberMap(c => c.DeclaringType).SetElementName(ErrorFieldNames.DeclaringType);
                    cmm.GetMemberMap(c => c.Name).SetElementName(ErrorFieldNames.Name);
                    cmm.GetMemberMap(c => c.ModuleId).SetElementName(ErrorFieldNames.ModuleId);
                    cmm.GetMemberMap(c => c.IsSignatureTarget).SetElementName(ErrorFieldNames.IsSignatureTarget);
                    cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.Method)obj).ExtendedData.Any());
                    cmm.GetMemberMap(c => c.GenericArguments).SetElementName(ErrorFieldNames.GenericArguments).SetShouldSerializeMethod(obj => ((Method)obj).GenericArguments.Any());
//.........这里部分代码省略.........
开发者ID:hanu412,项目名称:Exceptionless,代码行数:101,代码来源:MigrationJobBase.cs

示例9: RegisterTrackablePocoMap

        public static bool RegisterTrackablePocoMap(Type trackablePocoType)
        {
            if (BsonClassMap.IsClassMapRegistered(trackablePocoType))
                return false;

            var classMap = new BsonClassMap(trackablePocoType);
            var pocoType = TrackableResolver.GetPocoType(trackablePocoType);

            // start with auto map
            classMap.AutoMap();

            // ignore extra elements for smooth schema change
            classMap.SetIgnoreExtraElements(true);

            // unmap all members which T doesn't have
            var propertyNames = new HashSet<string>(pocoType.GetProperties().Select(p => p.Name));
            var deletingMembers = classMap.DeclaredMemberMaps.Where(m =>
            {
                var propertyInfo = m.MemberInfo as PropertyInfo;
                return propertyInfo == null ||
                       propertyNames.Contains(propertyInfo.Name) == false;
            }).ToList();
            foreach (var m in deletingMembers)
                classMap.UnmapMember(m.MemberInfo);

            // set default ignore for saving spaces
            foreach (var memberMap in classMap.DeclaredMemberMaps)
            {
                var mt = memberMap.MemberType;
                var defaultValue = mt.IsValueType ? Activator.CreateInstance(mt) : null;
                memberMap.SetDefaultValue(defaultValue);
                memberMap.SetIgnoreIfDefault(true);
            }

            // tell customized id to mongo-db
            var identityColumn = pocoType.GetProperties().FirstOrDefault(
                p => TrackablePropertyAttribute.GetParameter(p, "mongodb.identity") != null);
            if (identityColumn != null)
            {
                classMap.MapIdProperty(identityColumn.Name);
            }

            try
            {
                BsonClassMap.RegisterClassMap(classMap);
            }
            catch (ArgumentException)
            {
                // if duplicate key exists
                return false;
            }
            
            return true;
        }
开发者ID:cupsster,项目名称:TrackableData,代码行数:54,代码来源:TypeMapper.cs


注:本文中的BsonClassMap.AutoMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。