public override void OnBsonClassMap(BsonClassMap <PedidoOculos> map) { map.MapMember(x => x.OculosId); map.MapMember(x => x.PedidoId); map.MapMember(x => x.Oculos); map.MapMember(x => x.Pedido); }
private void OptInMembersWithBsonMemberMapModifierAttribute(BsonClassMap classMap) { // let other fields opt-in if they have any IBsonMemberMapAttribute attributes foreach (var fieldInfo in classMap.ClassType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { #pragma warning disable 618 // obsoleted by IBsonMemberMapModifier var hasAttribute = fieldInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any() || fieldInfo.GetCustomAttributes(typeof(IBsonMemberMapModifier), false).Any(); #pragma warning restore 618 if (hasAttribute) { classMap.MapMember(fieldInfo); } } // let other properties opt-in if they have any IBsonMemberMapAttribute attributes foreach (var propertyInfo in classMap.ClassType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { #pragma warning disable 618 // obsoleted by IBsonMemberMapModifier var hasAttribute = propertyInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any() || propertyInfo.GetCustomAttributes(typeof(IBsonMemberMapModifier), false).Any(); #pragma warning restore 618 if (hasAttribute) { classMap.MapMember(propertyInfo); } } }
public override void Map(BsonClassMap <Enumeration> cm) { cm.MapMember(x => x.Id); cm.MapMember(x => x.Name); cm.AddKnownType(typeof(BlockType)); cm.AddKnownType(typeof(Behavior)); }
private void OptInMembersWithBsonMemberMapModifierAttribute(BsonClassMap classMap) { // let other fields opt-in if they have any IBsonMemberMapAttribute attributes foreach (var fieldInfo in classMap.ClassType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { #if NETCORE50 || NETSTANDARD1_5 || NETSTANDARD1_6 var hasAttribute = fieldInfo.CustomAttributes?.Any(c => c.AttributeType is IBsonMemberMapAttribute); #else var hasAttribute = fieldInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false)?.Any(); #endif if (hasAttribute.HasValue && hasAttribute.Value) { classMap.MapMember(fieldInfo); } } // let other properties opt-in if they have any IBsonMemberMapAttribute attributes foreach (var propertyInfo in classMap.ClassType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { #if NETCORE50 || NETSTANDARD1_5 || NETSTANDARD1_6 var hasAttribute = propertyInfo.CustomAttributes?.Any(c => c.AttributeType is IBsonMemberMapAttribute); #else var hasAttribute = propertyInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false)?.Any(); #endif if (hasAttribute.HasValue && hasAttribute.Value) { classMap.MapMember(propertyInfo); } } }
public override void OnBsonClassMap(BsonClassMap <Oculos> map) { map.MapMember(x => x.Adicao).SetIsRequired(true); map.MapMember(x => x.ALT).SetIsRequired(true); map.MapMember(x => x.Cor).SetIsRequired(true); map.MapMember(x => x.DP).SetIsRequired(true); map.MapMember(x => x.PedidoOculosId).SetIsRequired(true); }
public override void OnBsonClassMap(BsonClassMap <Contato> map) { map.MapMember(x => x.Nome).SetIsRequired(true); map.MapMember(x => x.Telefone).SetIsRequired(true); map.MapMember(x => x.ClienteId).SetIsRequired(false); map.MapMember(x => x.Email).SetIsRequired(true); map.MapMember(x => x.Cliente); }
public override void OnBsonClassMap(BsonClassMap <Lente> map) { map.MapMember(x => x.Cyl); map.MapMember(x => x.Eixo); map.MapMember(x => x.Grau); map.MapMember(x => x.OculosId); map.MapMember(x => x.LenteType); }
public void Configure(BsonClassMap <Integration> classMap) { classMap.AutoMap(); classMap.MapIdMember(c => c.Id); classMap.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); classMap.MapMember(c => c.NickName).SetElementName("nickName"); classMap.MapMember(c => c.Props).SetElementName("props"); classMap.MapMember(c => c.Type).SetElementName("type"); }
public static void Register(BsonClassMap <BaseState> cm) { cm.AutoMap(); cm.SetIsRootClass(true); cm.SetIgnoreExtraElements(true); cm.MapMember(s => s.Nodes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, NodeInformation> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.Indexes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Index> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.ClusterTasks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, BaseTask> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.Locks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Lock> >(DictionaryRepresentation.ArrayOfArrays)); }
public void TestConvention(BsonType value) { var convention = new EnumRepresentationConvention(value); var classMap = new BsonClassMap<TestClass>(); var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum); var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum); var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum); convention.Apply(nonEnumMemberMap); convention.Apply(changedEnumMemberMap); Assert.AreEqual(value, ((IRepresentationConfigurable)(changedEnumMemberMap.GetSerializer())).Representation); }
public void TestConvention(BsonType value) { var convention = new EnumRepresentationConvention(value); var classMap = new BsonClassMap <TestClass>(); var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum); var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum); var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum); convention.Apply(nonEnumMemberMap); convention.Apply(changedEnumMemberMap); Assert.AreEqual(value, ((IRepresentationConfigurable)(changedEnumMemberMap.GetSerializer())).Representation); }
public void TestConvention(BsonType value) { var convention = new EnumRepresentationConvention(value); var classMap = new BsonClassMap<TestClass>(); var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum); var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum); var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum); convention.Apply(nonEnumMemberMap); convention.Apply(changedEnumMemberMap); Assert.IsNull(nonEnumMemberMap.SerializationOptions); Assert.IsNull(defaultEnumMemberMap.SerializationOptions); Assert.AreEqual(value, ((RepresentationSerializationOptions)changedEnumMemberMap.SerializationOptions).Representation); }
public void TestCamelCaseElementNameConvention() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap<TestClass>(); convention.Apply(classMap.MapMember(x => x.FirstName)); convention.Apply(classMap.MapMember(x => x.Age)); convention.Apply(classMap.MapMember(x => x._DumbName)); convention.Apply(classMap.MapMember(x => x.lowerCase)); Assert.AreEqual("firstName", classMap.GetMemberMap(x => x.FirstName).ElementName); Assert.AreEqual("age", classMap.GetMemberMap(x => x.Age).ElementName); Assert.AreEqual("_DumbName", classMap.GetMemberMap(x => x._DumbName).ElementName); Assert.AreEqual("lowerCase", classMap.GetMemberMap(x => x.lowerCase).ElementName); }
public void TestConvention(BsonType value) { var convention = new EnumRepresentationConvention(value); var classMap = new BsonClassMap <TestClass>(); var nonEnumMemberMap = classMap.MapMember(x => x.NonEnum); var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum); var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum); convention.Apply(nonEnumMemberMap); convention.Apply(changedEnumMemberMap); Assert.IsNull(nonEnumMemberMap.SerializationOptions); Assert.IsNull(defaultEnumMemberMap.SerializationOptions); Assert.AreEqual(value, ((RepresentationSerializationOptions)changedEnumMemberMap.SerializationOptions).Representation); }
public void TestCamelCaseElementNameConvention() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap <TestClass>(); convention.Apply(classMap.MapMember(x => x.FirstName)); convention.Apply(classMap.MapMember(x => x.Age)); convention.Apply(classMap.MapMember(x => x._DumbName)); convention.Apply(classMap.MapMember(x => x.lowerCase)); Assert.Equal("firstName", classMap.GetMemberMap(x => x.FirstName).ElementName); Assert.Equal("age", classMap.GetMemberMap(x => x.Age).ElementName); Assert.Equal("_DumbName", classMap.GetMemberMap(x => x._DumbName).ElementName); Assert.Equal("lowerCase", classMap.GetMemberMap(x => x.lowerCase).ElementName); }
public override void OnBsonClassMap(BsonClassMap <Cliente> map) { map.MapMember(x => x.Cpf).SetIsRequired(true); map.MapMember(x => x.Endereco); map.MapMember(x => x.Filiacao).SetIsRequired(true); map.MapMember(x => x.Nascimento).SetIsRequired(true); map.MapMember(x => x.Nome).SetIsRequired(true); map.MapMember(x => x.Rg).SetIsRequired(true); map.MapMember(x => x.Sexo).SetIsRequired(true); map.MapMember(x => x.IsSPC).SetIsRequired(false); map.MapMember(x => x.Contatos).SetIsRequired(false); }
public override void OnBsonClassMap(BsonClassMap <Pedido> map) { map.MapMember(x => x.ClienteId).SetIsRequired(true); map.MapMember(x => x.DataEntrega).SetIsRequired(true); map.MapMember(x => x.DataSolicitacao).SetIsRequired(true); map.MapMember(x => x.FaturaId).SetIsRequired(true); map.MapMember(x => x.Fatura); map.MapMember(x => x.Medico).SetIsRequired(true); map.MapMember(x => x.Obs).SetIsRequired(false); map.MapMember(x => x.Preco).SetIsRequired(true); map.MapMember(x => x.Servico).SetIsRequired(true); }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { definition.Relationships = GetEntityRelationships(definition).ToArray(); var removeProperties = new HashSet <string>(); foreach (var relationship in definition.Relationships) { if (relationship.IsCollection) { var memberMap = classMap.MapMember(relationship.NavigationProperty.PropertyInfo); var serializerType = typeof(EntityNavigationCollectionSerializer <>).MakeGenericType(relationship.EntityType); var collectionSerializer = Activator.CreateInstance(serializerType, relationship.IdProperty) as IBsonSerializer; memberMap.SetSerializer(collectionSerializer); } else { removeProperties.Add(relationship.NavigationProperty.FullPath); classMap.UnmapMember(relationship.NavigationProperty.PropertyInfo); } } //Remove navigation properties definition.Properties = definition.Properties.Where(p => !removeProperties.Contains(p.FullPath)).ToArray(); }
public void TestShouldDowncaseOnlyFirstCharByDefault() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap<TestClass>(); var firstName = classMap.MapMember(x => x.FirstName); var age = classMap.MapMember(x => x.Age); var allCaps = classMap.MapMember(x => x.ALLCAPS); convention.Apply(firstName); convention.Apply(age); convention.Apply(allCaps); Assert.AreEqual("firstName", firstName.ElementName); Assert.AreEqual("age", age.ElementName); Assert.AreEqual("aLLCAPS", allCaps.ElementName); }
public void Apply(BsonClassMap classMap) { if (classMap.ClassType.IsAbstract) { return; } var readOnlyProperties = classMap .ClassType .GetTypeInfo() .GetProperties(_bindingFlags) .Where(p => IsReadOnlyProperty(classMap, p)) .ToList(); foreach (var method in classMap.ClassType.GetMethods()) { var matchProperties = GetMatchingProperties(method, readOnlyProperties); if (matchProperties.Any()) { // Map properties foreach (var p in matchProperties) { classMap.MapMember(p); } } } }
public static BsonClassMap <TClass> MapCallistoDatetimeOffset <TClass, TMember>(this BsonClassMap <TClass> map, Expression <Func <TClass, TMember> > memberLambda) where TClass : class, IDocumentRoot { map.MapMember(memberLambda) .SetSerializer(DateTimeOffsetSerializerCustom.Instance); return(map); }
public void GivenACamelCaseConventionPack_WhenAppliedToAClassInheritingFromIndexIdentityBase_ThenPropertyNamesComeOutAsCamelCase() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap <TestClass>(); convention.Apply(classMap.MapMember(x => x.FirstNames)); convention.Apply(classMap.MapMember(x => x.LastName)); convention.Apply(classMap.MapMember(x => x.Title)); convention.Apply(classMap.MapMember(x => x.Salutation)); Assert.Equal("firstNames", classMap.GetMemberMap(x => x.FirstNames).ElementName); Assert.Equal("lastName", classMap.GetMemberMap(x => x.LastName).ElementName); Assert.Equal("title", classMap.GetMemberMap(x => x.Title).ElementName); Assert.Equal("salutation", classMap.GetMemberMap(x => x.Salutation).ElementName); }
protected override void Map(BsonClassMap <Access> map) { map.SetCollection("Authorizations"); map.MapMember(x => x.Key) .SetIsRequired(true); map.MapMember(x => x.Description) .SetIsRequired(false); map.MapMember(x => x.Name) .SetIsRequired(true); map.MapMember(x => x.Private) .SetIsRequired(true); }
public static void Register(BsonClassMap <GlobalValue> sm) { sm.AutoMap(); // sm.MapIdMember(c => c.Id); sm.MapMember(m => m.Name).SetIsRequired(true); sm.SetIgnoreExtraElements(true); }
public static void Register(BsonClassMap <Journal> journal) { journal.AutoMap(); journal.MapMember(c => c.JournalEntries).SetSerializer(new DictionaryInterfaceImplementerSerializer <SortedDictionary <int, JournalEntry> >(DictionaryRepresentation.ArrayOfDocuments)); journal.SetIgnoreExtraElements(true); //cm.SetIdMember(cm.GetMemberMap(c => c.Id)).SetIdGenerator(CombGuidGenerator.Instance); }
public void Apply(BsonClassMap classMap) { var readOnlyProperties = classMap .ClassType .GetTypeInfo() .GetProperties(_bindingFlags) .Where(p => IsReadOnlyProperty(classMap, p)) .ToList(); foreach (var constructor in classMap.ClassType.GetConstructors()) { // If we found a matching constructor then we map it and all the readonly properties var matchProperties = GetMatchingProperties(constructor, readOnlyProperties); if (matchProperties.Any()) { // Map constructor classMap.MapConstructor(constructor); // Map properties foreach (var p in matchProperties) { classMap.MapMember(p); } } } }
public static BsonMemberMap MapMyInterface2 <T>() where T : IMyInterface { var classMap = new BsonClassMap <T>(); classMap.AutoMap(); return(classMap.MapMember(t => t.SomeField2)); }
public void Apply(BsonClassMap classMap) { var members = _convention.FindMembers(classMap.ClassType); foreach (var member in members) { classMap.MapMember(member); } }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var definitionProperties = new List <IEntityProperty>(); foreach (var property in properties) { if (!property.CanRead || !property.CanWrite) { continue; } //Skip overridden properties var getMethod = property.GetMethod; if (property.GetMethod.IsVirtual && getMethod.GetBaseDefinition().DeclaringType != entityType) { continue; } //Skip indexer properties (eg. "this[int index]") if (property.GetIndexParameters().Length > 0) { continue; } //Skip properties with the "NotMappedAttribute" var notMappedAttribute = property.GetCustomAttribute <NotMappedAttribute>(); if (notMappedAttribute != null) { continue; } //Do the mapping var memberMap = classMap.MapMember(property); //Set custom element name with the "ColumnAttribute" var columnAttribute = property.GetCustomAttribute <ColumnAttribute>(); if (columnAttribute != null) { var mappedName = columnAttribute.Name; memberMap.SetElementName(mappedName); } definitionProperties.Add(new EntityProperty { EntityType = definition.EntityType, ElementName = memberMap.ElementName, FullPath = memberMap.ElementName, PropertyType = property.PropertyType, PropertyInfo = property }); } definition.Properties = definitionProperties; }
/// <inheritdoc /> public void Apply(BsonClassMap classMap) { var typeInfo = classMap.ClassType.GetTypeInfo(); if (typeInfo.IsAbstract) { return; } if (typeInfo.GetConstructor(Type.EmptyTypes) != null) { return; } var properties = typeInfo.GetProperties(); if (properties.Any(p => p.CanWrite)) { return; // a type that has any writable properties is not immutable } var anyConstructorsWereMapped = false; foreach (var ctor in typeInfo.GetConstructors()) { var parameters = ctor.GetParameters(); if (parameters.Length != properties.Length) { continue; // only consider constructors that have sufficient parameters to initialize all properties } var matches = parameters .GroupJoin(properties, parameter => parameter.Name, property => property.Name, (parameter, props) => new { Parameter = parameter, Properties = props }, StringComparer.OrdinalIgnoreCase); if (matches.Any(m => m.Properties.Count() != 1)) { continue; } classMap.MapConstructor(ctor); anyConstructorsWereMapped = true; } if (anyConstructorsWereMapped) { // if any constructors were mapped by this convention then map all the properties also foreach (var property in properties) { classMap.MapMember(property); } } }
public override void OnBsonClassMap(BsonClassMap <Fatura> map) { map.MapMember(x => x.DataPagamento).SetIsRequired(true); map.MapMember(x => x.FormaPagamento).SetIsRequired(true); map.MapMember(x => x.NumeroParcelas); map.MapMember(x => x.PedidoId).SetIsRequired(true); map.MapMember(x => x.Parcelas); map.MapMember(x => x.Sinal).SetIsRequired(true); map.MapMember(x => x.Total).SetIsRequired(true); map.MapMember(x => x.Valor).SetIsRequired(true); }
public override void OnBsonClassMap(BsonClassMap <Endereco> map) { map.MapMember(x => x.Bairro).SetIsRequired(true); map.MapMember(x => x.Cep).SetIsRequired(true); map.MapMember(x => x.Cidade).SetIsRequired(true); map.MapMember(x => x.ClienteId).SetIsRequired(false); map.MapMember(x => x.Complemento).SetIsRequired(false); map.MapMember(x => x.Estado).SetIsRequired(true); map.MapMember(x => x.Logradouro).SetIsRequired(true); map.MapMember(x => x.Numero).SetIsRequired(false); }
public void TestApply(bool value) { var subject = new IgnoreIfDefaultConvention(value); var classMap = new BsonClassMap<TestClass>(); var memberMap = classMap.MapMember(x => x.Id); subject.Apply(memberMap); Assert.AreEqual(value, memberMap.IgnoreIfDefault); }
public void TestShouldNotChangeIfAlreadyCamelCased() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap<TestClass>(); var lowerCase = classMap.MapMember(x => x.camelCasedName); convention.Apply(lowerCase); Assert.AreEqual("camelCasedName", lowerCase.ElementName); }
public void TestShouldHandleNameStartingWithNonLetter() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap<TestClass>(); var _dumbName = classMap.MapMember(x => x._dumbName); convention.Apply(_dumbName); Assert.AreEqual("_dumbName", _dumbName.ElementName); }
public void TestConventionOverride() { var int64Convention = new EnumRepresentationConvention(BsonType.Int64); var strConvention = new EnumRepresentationConvention(BsonType.String); var classMap = new BsonClassMap<TestClass>(); var memberMap = classMap.MapMember(x => x.ChangedRepresentationEnum); int64Convention.Apply(memberMap); strConvention.Apply(memberMap); Assert.AreEqual(BsonType.String, ((IRepresentationConfigurable)(memberMap.GetSerializer())).Representation); }
public void TestShouldDowncaseCertainNumberOfChars(int charsToDowncase, string expected) { var convention = new CamelCaseElementNameConvention(charsToDowncase); var classMap = new BsonClassMap<TestClass>(); var ioStream = classMap.MapMember(x => x.ALLCAPS); convention.Apply(ioStream); Assert.AreEqual(expected, ioStream.ElementName); }
// private methods private void MapField(BsonClassMap classMap, FieldInfo fieldInfo) { if (fieldInfo.IsInitOnly || fieldInfo.IsLiteral) { // we can't write return; } classMap.MapMember(fieldInfo); }
public void TestCamelCaseElementNameConvention() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap<TestClass>(); var firstName = classMap.MapMember(x => x.FirstName); var age = classMap.MapMember(x => x.Age); var _dumbName = classMap.MapMember(x => x._DumbName); var lowerCase = classMap.MapMember(x => x.lowerCase); convention.Apply(firstName); convention.Apply(age); convention.Apply(_dumbName); convention.Apply(lowerCase); Assert.AreEqual("firstName", firstName.ElementName); Assert.AreEqual("age", age.ElementName); Assert.AreEqual("_DumbName", _dumbName.ElementName); Assert.AreEqual("lowerCase", lowerCase.ElementName); }
public void TestCamelCaseElementNameConvention() { var convention = new CamelCaseElementNameConvention(); var classMap = new BsonClassMap <TestClass>(); var firstName = classMap.MapMember(x => x.FirstName); var age = classMap.MapMember(x => x.Age); var _dumbName = classMap.MapMember(x => x._DumbName); var lowerCase = classMap.MapMember(x => x.lowerCase); convention.Apply(firstName); convention.Apply(age); convention.Apply(_dumbName); convention.Apply(lowerCase); Assert.AreEqual("firstName", firstName.ElementName); Assert.AreEqual("age", age.ElementName); Assert.AreEqual("_DumbName", _dumbName.ElementName); Assert.AreEqual("lowerCase", lowerCase.ElementName); }
public void Test() { var convention = new DelegateMemberMapConvention("test", m => m.SetElementName("blah")); Assert.AreEqual("test", convention.Name); var classMap = new BsonClassMap<TestClass>(); var member = classMap.MapMember(x => x.FirstName); convention.Apply(member); Assert.AreEqual("blah", member.ElementName); }
public void Apply(BsonClassMap classMap) { var memberName = _convention.FindIdMember(classMap.ClassType); if (string.IsNullOrEmpty(memberName)) { return; } var memberInfo = classMap.ClassType.GetMember(memberName, MemberTypes.Field | MemberTypes.Property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).SingleOrDefault(); if (memberInfo == null) { return; } classMap.SetIdMember(classMap.MapMember(memberInfo)); }
private BsonClassMap BuildClassMap(Type type, ProjectionMapping mapping) { if (type == null || type == typeof(object)) { return null; } var baseClassMap = BuildClassMap(type.GetTypeInfo().BaseType, mapping); if (baseClassMap != null) { baseClassMap.Freeze(); } var classMap = new BsonClassMap(type, baseClassMap); 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; }
private void OptInMembersWithBsonMemberMapModifierAttribute(BsonClassMap classMap) { // let other fields opt-in if they have any IBsonMemberMapAttribute attributes foreach (var fieldInfo in classMap.ClassType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { var hasAttribute = fieldInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any(); if (hasAttribute) { classMap.MapMember(fieldInfo); } } // let other properties opt-in if they have any IBsonMemberMapAttribute attributes foreach (var propertyInfo in classMap.ClassType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { var hasAttribute = propertyInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Any(); if (hasAttribute) { classMap.MapMember(propertyInfo); } } }
private void MapProperty(BsonClassMap classMap, PropertyInfo propertyInfo) { if (!propertyInfo.CanRead || (!propertyInfo.CanWrite && classMap.ClassType.Namespace != null)) { // we can't write or it is anonymous... return; } // skip indexers if (propertyInfo.GetIndexParameters().Length != 0) { return; } // skip overridden properties (they are already included by the base class) var getMethodInfo = propertyInfo.GetGetMethod(true); if (getMethodInfo.IsVirtual && getMethodInfo.GetBaseDefinition().DeclaringType != classMap.ClassType) { return; } classMap.MapMember(propertyInfo); }