コード例 #1
0
        /// <summary>
        /// Get all default property mappers for the given types.
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TDestination"></typeparam>
        /// <returns></returns>
        public static IEnumerable <IPropertyMapper <TSource, TDestination> > GetDefaultPropertyMappers
        <TSource, TDestination>(ITransformerResolver resolver)
            where TSource : class
            where TDestination : class
        {
            IEnumerable <KeyValuePair <PropertyInfo, PropertyInfo> > matchedProperties = FactoryMapper.GetSuitedPropertiesOf(typeof(TSource), typeof(TDestination));
            HashSet <IPropertyMapper <TSource, TDestination> >       mappers           = new HashSet <IPropertyMapper <TSource, TDestination> >();

            foreach (var current in matchedProperties)
            {
                try
                {
                    Action <TSource, TDestination> action = DynamicPropertyMap <TSource, TDestination>(current.Key,
                                                                                                       current.Value);
                    mappers.Add(new PropertyMapper <TSource, TDestination>(action, current.Key.Name, current.Value.Name));
                }
                catch (InconsistentMappingException)
                {
                    // exceptions must be managed..
                    // so in this means that properties are not compatibles..
                    try
                    {
                        if (resolver != null)
                        {
                            Action <TSource, TDestination> action = DynamicPropertyMap <TSource, TDestination>(current.Key, current.Value, resolver);
                            mappers.Add(new PropertyMapper <TSource, TDestination>(action));
                        }
                    }
                    catch
                    {
                    }
                }
                catch
                {
                }
            }
            return(mappers);
        }
コード例 #2
0
        /// <summary>
        /// Gets the default property mappers.
        /// </summary>
        /// <param name="sourceType">Type of the source.</param>
        /// <param name="destinationType">Type of the destination.</param>
        /// <param name="resolver">The resolver.</param>
        /// <returns></returns>
        public static IEnumerable <IPropertyMapper> GetDefaultPropertyMappers(Type sourceType, Type destinationType, ITransformerResolver resolver)
        {
            IEnumerable <KeyValuePair <PropertyInfo, PropertyInfo> > matchedProperties = FactoryMapper.GetSuitedPropertiesOf(sourceType, destinationType);
            HashSet <IPropertyMapper> mappers = new HashSet <IPropertyMapper>();

            foreach (var current in matchedProperties)
            {
                try
                {
                    mappers.Add(new PropertyMapper(current.Key, current.Value));
                }
                catch (InconsistentMappingException)
                {
                    // exceptions must be managed..
                    // so in this means that properties are not compatibles..
                    try
                    {
                        if (resolver != null)
                        {
                            mappers.Add(new PropertyMapper(current.Key, current.Value, resolver));
                        }
                    }
                    catch
                    {
                    }
                }
                catch
                {
                }
            }

            return(mappers);
        }
コード例 #3
0
 /// <summary>
 /// Build a dynamic merger for all compatibles properties between source type with destination type.
 /// </summary>
 /// <typeparam name="TSource"></typeparam>
 /// <typeparam name="TDestination"></typeparam>
 /// <returns></returns>
 public static ISourceMerger <TSource, TDestination> DynamicResolutionMerger <TSource, TDestination>()
     where TSource : class
     where TDestination : class
 {
     return(FactoryMapper.DynamicResolutionMerger <TSource, TDestination>(null, null));
 }