Beispiel #1
0
 public static BasicTypes GetConversionType(Type innType, Type outType)
 {
     if (innType.Implements <IDictionary>() && outType.Implements <IDictionary>())
     {
         return(BasicTypes.Dictionary);
     }
     if (innType.Implements <IEnumerable>() && outType.Implements <IEnumerable>() && !innType.IsValueType())
     {
         return(BasicTypes.List);
     }
     if (innType.IsValueType() && outType.IsValueType() || TypeExtensions.CanConvert(outType, innType))
     {
         return(BasicTypes.Convertable);
     }
     return(BasicTypes.ComplexType);
 }
Beispiel #2
0
        public IAutomapRules GetRule(Type innType, Type outType, bool doMerge)
        {
            var           key = new KeyValuePair <Type, Type>(innType, outType);
            IAutomapRules rule;

            Rules.TryGetValue(key, out rule);
            if (rule != null)
            {
                return(rule);
            }
            if (!TypeExtensions.CanConvert(outType, innType))
            {
                throw new ArgumentOutOfRangeException(string.Format("Cannot find mapping for type{0}->{1}", innType, outType));
            }
            return(new AutomapRules <object, object> {
                BasicType = doMerge ? BasicTypes.ComplexType : BasicTypes.Convertable, Parent = this, OutType = outType, InType = innType
            });
        }
Beispiel #3
0
        internal void MapDictionary(IAutomapRules map, PropertyInfo innPropertyInfo, PropertyInfo outPropertyInfo)
        {
            var innGenericType  = innPropertyInfo.PropertyType.GetGenericArguments()[0];
            var outGenericType  = outPropertyInfo.PropertyType.GetGenericArguments()[0];
            var innGenericType2 = innPropertyInfo.PropertyType.GetGenericArguments()[1];
            var outGenericType2 = outPropertyInfo.PropertyType.GetGenericArguments()[1];

            if (TypeExtensions.CanConvert(outGenericType, innGenericType) &&
                TypeExtensions.CanConvert(outGenericType2, innGenericType2))
            {
                map.Fields.Add(new KeyValuePair <string, IMapRules>(innPropertyInfo.Name,
                                                                    new MapRules
                {
                    InMemberName  = innPropertyInfo.Name,
                    OutMemberName = outPropertyInfo.Name,
                    Convertible   = true,
                    BasicType     = BasicTypes.Dictionary,
                    Parent        = Parent
                }));
            }
            else if (TypeExtensions.CanConvert(outGenericType, innGenericType))
            {
                map.Fields.Add(new KeyValuePair <string, IMapRules>(innPropertyInfo.Name,
                                                                    new MapRules
                {
                    InMemberName  = innPropertyInfo.Name,
                    OutMemberName = outPropertyInfo.Name,
                    Convertible   = false,
                    BasicType     = BasicTypes.Dictionary,
                    Parent        = Parent
                }));
                if (!map.Parent.ContainsRule(new KeyValuePair <Type, Type>(innGenericType2, outGenericType2)))
                {
                    map.Parent.AddMap(innGenericType2, outGenericType2);
                }
            }
        }