public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (var property in properties) { var propertyType = property.PropertyType; //Maps the property type for handling property nesting if (propertyType.IsClass && propertyType != entityType) { if (!EntityMapping.IsRegistered(propertyType)) { EntityMapping.RegisterType(propertyType); } } else if ( propertyType.IsGenericType && propertyType.GetGenericArguments().Count() == 1 && ( propertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>) || propertyType.GetInterfaces().Where(i => i.IsGenericType).Any(i => i.GetGenericTypeDefinition() == typeof(IEnumerable <>)) ) ) { var genericType = propertyType.GetGenericArguments()[0]; if (!EntityMapping.IsRegistered(genericType)) { EntityMapping.RegisterType(genericType); } } } }
private IBsonSerializer GetRealSerializer(Type type) { if (type == typeof(object)) { return(new DictionaryInterfaceImplementerSerializer <Dictionary <string, object> >()); } else if (type.IsGenericType && DictionaryTypes.Contains(type.GetGenericTypeDefinition())) { var serializerType = typeof(DictionaryInterfaceImplementerSerializer <>).MakeGenericType(type); var serializer = (IBsonSerializer)Activator.CreateInstance(serializerType); return(serializer); } else { if (type.IsClass && type != typeof(string)) { //Force the type to be processed by the Entity Mapper if (!EntityMapping.IsRegistered(type)) { EntityMapping.RegisterType(type); } var classMap = BsonClassMap.LookupClassMap(type); var serializerType = typeof(BsonClassMapSerializer <>).MakeGenericType(type); var serializer = (IBsonSerializer)Activator.CreateInstance(serializerType, classMap); return(serializer); } else { return(BsonSerializer.LookupSerializer(type)); } } }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; if (entityType != typeof(object) && entityType != typeof(object) && !EntityMapping.IsRegistered(entityType.BaseType)) { EntityMapping.RegisterType(entityType.BaseType); } else { classMap.SetIsRootClass(true); } }
private IBsonSerializer GetRealSerializer(Type type) { //Force the type to be processed by the Entity Mapper if (!EntityMapping.IsRegistered(type)) { EntityMapping.RegisterType(type); } var classMap = BsonClassMap.LookupClassMap(type); var serializerType = typeof(BsonClassMapSerializer <>).MakeGenericType(type); var serializer = (IBsonSerializer)Activator.CreateInstance(serializerType, classMap); return(serializer); }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; var bsonKnownTypesAttribute = entityType.GetCustomAttribute <BsonKnownTypesAttribute>(); if (bsonKnownTypesAttribute != null) { foreach (var type in bsonKnownTypesAttribute.KnownTypes) { if (!EntityMapping.IsRegistered(type)) { EntityMapping.RegisterType(type); } } } }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; var properties = definition.Properties; foreach (var property in properties) { var propertyType = property.PropertyType; propertyType = propertyType.GetEnumerableItemTypeOrDefault(); //Maps the property type for handling property nesting if (propertyType.IsClass && propertyType != entityType && propertyType != typeof(string)) { if (!EntityMapping.IsRegistered(propertyType)) { EntityMapping.RegisterType(propertyType); } } } }
public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (var property in properties) { var propertyType = property.PropertyType; propertyType = propertyType.GetEnumerableItemTypeOrDefault(); //Maps the property type for handling property nesting if (propertyType.IsClass && propertyType != entityType) { if (!EntityMapping.IsRegistered(propertyType)) { EntityMapping.RegisterType(propertyType); } } } }