public void AfterPropertiesSet() { var defaultProfile = ConventionProfile.GetDefault(); _profile = new ConventionProfile(); _filter = new ConventionFilterHelper(IncludeFilters, ExcludeFilters); _profile.SetDefaultValueConvention(DefaultValueConvention ?? defaultProfile.DefaultValueConvention); _profile.SetElementNameConvention(ElementNameConvention ?? defaultProfile.ElementNameConvention); _profile.SetExtraElementsMemberConvention(ExtraElementsMemberConvention ?? defaultProfile.ExtraElementsMemberConvention); _profile.SetIdGeneratorConvention(IdGeneratorConvention ?? defaultProfile.IdGeneratorConvention); _profile.SetIdMemberConvention(IdMemberConvention ?? defaultProfile.IdMemberConvention); _profile.SetIgnoreExtraElementsConvention(IgnoreExtraElementsConvention ?? defaultProfile.IgnoreExtraElementsConvention); _profile.SetIgnoreIfDefaultConvention(IgnoreIfDefaultConvention ?? defaultProfile.IgnoreIfDefaultConvention); _profile.SetIgnoreIfNullConvention(IgnoreIfNullConvention ?? defaultProfile.IgnoreIfNullConvention); _profile.SetMemberFinderConvention(MemberFinderConvention ?? defaultProfile.MemberFinderConvention); _profile.SetSerializationOptionsConvention(SerializationOptionsConvention ?? defaultProfile.SerializationOptionsConvention); BsonClassMap.RegisterConventions(_profile, _filter.Filter); }
private void Register(IDefinitionProvider[] definitionProviders, IProxyFactory proxies) { if (isRegistered) { return; } isRegistered = true; var conventions = new ConventionProfile(); conventions.SetIgnoreIfNullConvention(new AlwaysIgnoreIfNullConvention()); conventions.SetMemberFinderConvention(new IgnoreUnderscoreMemberFinderConvention()); BsonClassMap.RegisterConventions(conventions, t => true); BsonSerializer.RegisterSerializationProvider(new ContentSerializationProvider(this, proxies)); BsonClassMap.RegisterClassMap <AuthorizedRole>(cm => { cm.AutoMap(); cm.UnmapProperty(cd => cd.ID); cm.UnmapField(cd => cd.EnclosingItem); }); BsonClassMap.RegisterClassMap <ContentDetail>(cm => { cm.AutoMap(); cm.UnmapProperty(cd => cd.ID); cm.UnmapProperty(cd => cd.EnclosingCollection); cm.UnmapProperty(cd => cd.EnclosingItem); cm.UnmapProperty(cd => cd.Value); cm.MapProperty(cd => cd.LinkedItem).SetSerializer(new ContentRelationSerializer(this)); cm.UnmapProperty(cd => cd.LinkValue); cm.GetMemberMap(cd => cd.DateTimeValue).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); }); BsonClassMap.RegisterClassMap <DetailCollection>(cm => { cm.AutoMap(); cm.UnmapProperty(dc => dc.ID); cm.UnmapProperty(dc => dc.EnclosingItem); }); BsonClassMap.RegisterClassMap <Relation <ContentItem> >(cm => { cm.MapProperty(r => r.ID); cm.MapProperty(r => r.ValueAccessor).SetSerializer(new RelationValueAccessorSerializer <ContentItem>(this)); }); BsonClassMap.RegisterClassMap <ContentRelation>(cm => { }); BsonClassMap.RegisterClassMap <ContentVersion>(cm => { cm.AutoMap(); cm.MapIdProperty(cv => cv.ID).SetIdGenerator(new IntIdGenerator()); cm.GetMemberMap(cv => cv.Published).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(cv => cv.Saved).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(cv => cv.FuturePublish).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(cv => cv.Expired).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); }); BsonClassMap.RegisterClassMap <ContentItem>(cm => { cm.AutoMap(); cm.MapIdProperty(ci => ci.ID).SetIdGenerator(new IntIdGenerator()); cm.UnmapProperty(ci => ci.Children); cm.GetMemberMap(ci => ci.Parent).SetSerializer(new ContentItemReferenceSerializer(this)); cm.UnmapProperty(ci => ci.VersionOf); cm.GetMemberMap(ci => ci.Created).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(ci => ci.Updated).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(ci => ci.Published).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.GetMemberMap(ci => ci.Expires).SetSerializationOptions(new DateTimeSerializationOptions(DateTimeKind.Local)); cm.SetIsRootClass(isRootClass: true); }); var definitions = definitionProviders.SelectMany(dp => dp.GetDefinitions()).ToList(); foreach (var definition in definitions) { var factoryType = typeof(ContentClassMapFactory <>).MakeGenericType(definition.ItemType); var factory = (ContentClassMapFactory)Activator.CreateInstance(factoryType, proxies, this, services); BsonClassMap.RegisterClassMap(factory.Create(definition, definitions)); } }