예제 #1
0
        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);
        }
예제 #2
0
 public DtoEntityMappingProperties(MapToEntityProperty dtoMapToentityProperty, PropertyInfo dtoPropertyInfo, PropertyInfo entityPropertyInfo)
 {
     DtoPropertyInfo        = dtoPropertyInfo;
     DtoMapToEntityProperty = dtoMapToentityProperty;
     EntityPropertyInfo     = entityPropertyInfo;
 }