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


C# BsonClassMap.SetIgnoreExtraElements方法代码示例

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


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

示例1: 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

示例2: Apply

 // public methods
 /// <summary>
 /// Applies a modification to the class map.
 /// </summary>
 /// <param name="classMap">The class map.</param>
 public void Apply(BsonClassMap classMap)
 {
     classMap.SetIgnoreExtraElements(_ignoreExtraElements);
     classMap.SetIgnoreExtraElementsIsInherited(_inherited);
 }
开发者ID:huoxudong125,项目名称:SequoiaDB.Charp,代码行数:10,代码来源:BsonIgnoreExtraElementsAttribute.cs

示例3: BuildClassMap

        private BsonClassMap BuildClassMap(Type type, ProjectionMapping mapping)
        {
            if (type == null || type == typeof(object))
            {
                return null;
            }

            var baseClassMap = BuildClassMap(type.BaseType, mapping);
            if (baseClassMap != null)
            {
                baseClassMap.Freeze();
            }
            var classMap = new BsonClassMap(type, baseClassMap);

            // Ignore extra elements, as the projection expression will likely not be complete
            classMap.SetIgnoreExtraElements(true);

            foreach (var memberMapping in mapping.Members.Where(x => x.Member.DeclaringType == type))
            {
                var serializationExpression = memberMapping.Expression as SerializationExpression;
                if (serializationExpression == null)
                {
                    var serializer = Build(memberMapping.Expression);
                    serializationExpression = new FieldExpression(
                        memberMapping.Member.Name,
                        serializer,
                        memberMapping.Expression);
                }

                var memberMap = classMap.MapMember(memberMapping.Member)
                    .SetSerializer(serializationExpression.Serializer)
                    .SetElementName(memberMapping.Member.Name);

                if (classMap.IdMemberMap == null && serializationExpression is GroupingKeyExpression)
                {
                    classMap.SetIdMember(memberMap);
                }
            }

            return classMap;
        }
开发者ID:bursauxa,项目名称:mongo-csharp-driver,代码行数:41,代码来源:SerializerBuilder.cs

示例4: Apply

 /// <summary>
 /// Applies a modification to the class map.
 /// </summary>
 /// <param name="classMap">The class map.</param>
 public void Apply(BsonClassMap classMap)
 {
     classMap.SetIgnoreExtraElements(_ignoreExtraElements);
 }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:8,代码来源:IgnoreExtraElementsConvention.cs

示例5: 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

示例6: 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

示例7: Apply

 public void Apply(BsonClassMap classMap)
 {
     var value = _convention.IgnoreExtraElements(classMap.ClassType);
     classMap.SetIgnoreExtraElements(value);
 }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:5,代码来源:ConventionProfile.cs

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