Beispiel #1
0
        internal Boolean TryMapping(MemberInfo miSrc, MemberInfo[] miDsts, bool ignoreMap = false, bool useAutoMapper = false)
        {
            IMemberGetter getter = CreateGetter(miSrc, ignoreMap);

            if (getter == null)
            {
                return(false);
            }
            return(TryMapping(getter, miDsts, ignoreMap, useAutoMapper));
        }
        private static ExpressionResolutionResult ExpressionResolutionResult(
            ExpressionResolutionResult expressionResolutionResult, IMemberGetter getter)
        {
            Expression currentChild = expressionResolutionResult.ResolutionExpression;
            Type currentChildType;
            var memberInfo = getter.MemberInfo;

            var propertyInfo = memberInfo as PropertyInfo;
            if (propertyInfo != null)
            {
                currentChild = Expression.Property(currentChild, propertyInfo);
                currentChildType = propertyInfo.PropertyType;
            }
            else
                currentChildType = currentChild.Type;

            return new ExpressionResolutionResult(currentChild, currentChildType);
        }
        private static ExpressionResolutionResult ExpressionResolutionResult(
            ExpressionResolutionResult expressionResolutionResult, IMemberGetter getter)
        {
            Expression currentChild = expressionResolutionResult.ResolutionExpression;
            Type       currentChildType;
            var        memberInfo = getter.MemberInfo;

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null)
            {
                currentChild     = Expression.Property(currentChild, propertyInfo);
                currentChildType = propertyInfo.PropertyType;
            }
            else
            {
                currentChildType = currentChild.Type;
            }

            return(new ExpressionResolutionResult(currentChild, currentChildType));
        }
Beispiel #4
0
 internal Boolean TryMapping(IMemberGetter getter, MemberInfo[] miDsts, bool ignoreMap = false, bool useAutoMapper = false)
 {
     foreach (MemberInfo miDst in miDsts)
     {
         IMemberSetter setter = MemberSetterCreator.For(miDst);
         if (setter == null)
         {
             continue;
         }
         if (setter.SetterType.IsAssignableFrom(getter.GetterType))
         {
             GettersAndSetters.Add(new GetterAndSetter(getter, setter));
         }
         else if (useAutoMapper)
         {
             GettersAndSetters.Add(new MapperGetterAndSetter(getter, setter, AutoMapper.Build(getter.GetterType, setter.SetterType)));
         }
         return(true);
     }
     return(false);
 }
 internal override void PrepareMapping()
 {
     ParameterInfo[] pis = ConstructorInfo.GetParameters();
     for (int i = 0; i < pis.Length; i++)
     {
         ParameterInfo piDst = pis[i];
         foreach (MemberInfo miSrc in KlassSrc.GetMember(piDst.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance))
         {
             IMemberGetter getter = CreateGetter(miSrc);
             if (getter != null)
             {
                 if (piDst.ParameterType.IsAssignableFrom(getter.GetterType))
                 {
                     Getters[i] = getter;
                 }
             }
         }
         if (Getters[i] == null)
         {
             Getters[i] = new DefaultGetter(pis[i]);
         }
     }
 }
        internal Boolean TryMapping(MemberInfo miSrc, MemberInfo[] miDsts, bool ignoreMap = false, bool useAutoMapper = false)
        {
            IMemberGetter getter = CreateGetter(miSrc, ignoreMap);

            if (getter == null)
            {
                return(false);
            }
            foreach (MemberInfo miDst in miDsts)
            {
                IMemberSetter setter = null;
                if (miDst.MemberType == MemberTypes.Property)
                {
                    setter = new PropertySetter((PropertyInfo)miDst);
                }
                else if (miDst.MemberType == MemberTypes.Field)
                {
                    setter = new FieldSetter((FieldInfo)miDst);
                }

                if (setter == null)
                {
                    return(false);
                }
                if (setter.SetterType.IsAssignableFrom(getter.GetterType))
                {
                    GettersAndSetters.Add(new GetterAndSetter(getter, setter));
                }
                else if (useAutoMapper)
                {
                    GettersAndSetters.Add(new MapperGetterAndSetter(getter, setter, AutoMapper.Build(getter.GetterType, setter.SetterType)));
                }
                return(true);
            }
            return(false);
        }
 public void AddParameter(ParameterInfo parameter, IMemberGetter[] resolvers, bool canResolve)
 {
     _ctorParams.Add(new ConstructorParameterMap(parameter, resolvers, canResolve));
 }
 public MapperGetterAndSetter(IMemberGetter getter, IMemberSetter setter, IMapper mapper)
 {
     Getter = getter;
     Setter = setter;
     Mapper = mapper;
 }
 public GetterAndSetter(IMemberGetter getter, IMemberSetter setter)
 {
     Getter = getter;
     Setter = setter;
 }
 public ConstructorParameterMap(ParameterInfo parameter, IMemberGetter[] sourceResolvers)
 {
     Parameter = parameter;
     SourceResolvers = sourceResolvers;
 }
 public ConstructorParameterMap(ParameterInfo parameter, IMemberGetter[] sourceResolvers, bool canResolve)
 {
     Parameter = parameter;
     SourceResolvers = sourceResolvers;
     CanResolve = canResolve;
 }