private static IList <DtoEntityMappingProperties> GetDtoEntityMappingProperties(Type dtoType, Type entityType) { Type entityTypeToUse = ExtractOriginalTypeIfTypeIsProxyClass(entityType); IList <DtoEntityMappingProperties> result = new List <DtoEntityMappingProperties>(); try { foreach (PropertyInfo dtoPropertyInfo in dtoType.GetProperties()) { MapToEntityProperty mapToEntityProperty = GetMapToEntityProperyAttributeIfPresent(dtoPropertyInfo); if (mapToEntityProperty != null) { PropertyInfo entityPropertyInfo = entityTypeToUse.GetProperty(mapToEntityProperty.EntityPropertyNameToMap); if (entityPropertyInfo == null) { ThrowEntityToDtoMappingException(String.Format("The Dto [{0}] used for the mapping has a property [{1}] that is mapped to an non-existent entity [{2}] property [{3}]. Fix the Dto mapping!", dtoType, dtoPropertyInfo.Name, entityType, mapToEntityProperty.EntityPropertyNameToMap)); } var dtoentityMappingProperties = new DtoEntityMappingProperties(mapToEntityProperty, dtoPropertyInfo, entityPropertyInfo); result.Add(dtoentityMappingProperties); } } } catch (MissingMethodException ex) { ThrowDtoToEntityMappingException(String.Format("There is a wrong Mapping attribute(MapToEntityProperty) in your dto. Cannot find specified property in your Entity: {0}", ex.Message)); } return(result); }
private object GetEntityUsingKnownResolver(object dtoToConvertInEntity, DtoEntityMappingProperties mapping) { var pInstanceDto = mapping.DtoPropertyInfo.GetValue(dtoToConvertInEntity, null); string key = mapping.DtoRegisterdResolverName; if (!_knowEntityResolverMappings.ContainsKey(key)) { ThrowDtoToEntityMappingException(String.Format("Please add a resolver with key [{0}] to instruct the adapter in how to create/obtain an instance of type {1} from dto's property {2}", key, mapping.EntityPropertyInfo.PropertyType.Name, mapping.DtoPropertyInfo.Name)); } return(_knowEntityResolverMappings[key](pInstanceDto)); }