public void ApplyMapping(Type entityType, BsonClassMap classMap) { //Ignore extra elements when the "IgnoreExtraElementsAttribute" is on the Entity var ignoreExtraElements = entityType.GetCustomAttribute <IgnoreExtraElementsAttribute>(); if (ignoreExtraElements != null) { classMap.SetIgnoreExtraElements(true); classMap.SetIgnoreExtraElementsIsInherited(ignoreExtraElements.IgnoreInherited); } else { //If any of the Entity's properties have the "ExtraElementsAttribute", assign that against the BsonClassMap var extraElementsProperty = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .Select(p => new { PropertyInfo = p, ExtraElementsAttribute = p.GetCustomAttribute <ExtraElementsAttribute>() }).Where(p => p.ExtraElementsAttribute != null).FirstOrDefault(); if (extraElementsProperty != null && typeof(IDictionary <string, object>).IsAssignableFrom(extraElementsProperty.PropertyInfo.PropertyType)) { classMap.SetExtraElementsMember(new BsonMemberMap(classMap, extraElementsProperty.PropertyInfo)); } } }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; //Ignore extra elements when the "IgnoreExtraElementsAttribute" is on the Entity var ignoreExtraElements = entityType.GetCustomAttribute <IgnoreExtraElementsAttribute>(); if (ignoreExtraElements != null) { classMap.SetIgnoreExtraElements(true); classMap.SetIgnoreExtraElementsIsInherited(ignoreExtraElements.IgnoreInherited); } else { classMap.SetIgnoreExtraElements(false); //If any of the Entity's properties have the "ExtraElementsAttribute", assign that against the BsonClassMap foreach (var property in definition.Properties) { var extraElementsAttribute = property.PropertyInfo.GetCustomAttribute <ExtraElementsAttribute>(); if (extraElementsAttribute != null && typeof(IDictionary <string, object>).IsAssignableFrom(property.PropertyType)) { foreach (var memberMap in classMap.DeclaredMemberMaps) { if (memberMap.ElementName == property.ElementName) { classMap.SetExtraElementsMember(memberMap); return; } } } } } }
private void RegisterId(Type type, string propertyName = "Uid") { if (!BsonClassMap.IsClassMapRegistered(type)) { var cm = new BsonClassMap(type); cm.AutoMap(); cm.MapIdProperty(propertyName).SetIdGenerator(UidGenerator.Instance); cm.SetIgnoreExtraElements(true); cm.SetIgnoreExtraElementsIsInherited(true); BsonClassMap.RegisterClassMap(cm); } }
private void Register3(Type type, bool autoMap = false) { if (!BsonClassMap.IsClassMapRegistered(type)) { var cm = new BsonClassMap(type); if (autoMap) { cm.AutoMap(); } cm.SetIgnoreExtraElements(true); cm.SetIgnoreExtraElementsIsInherited(true); BsonClassMap.RegisterClassMap(cm); } }
// 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); }
public void Apply(BsonClassMap classMap) { classMap.SetIgnoreExtraElements(true); classMap.SetIgnoreExtraElementsIsInherited(true); CallistoLogger.ConventionsLogger.Ignore(classMap.ClassType.Name); }