Ejemplo n.º 1
0
        /// <summary>
        /// 自动映射
        /// </summary>
        /// <typeparam name="To">目标对象</typeparam>
        /// <typeparam name="From">来源对象</typeparam>
        /// <param name="from">来源对象</param>
        /// <param name="target">目标对象,请实例化该对象</param>
        /// <param name="callBack">当完成映射后的回调</param>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        internal static To Map <From, To>(From from, To target, Action <From, To> callBack, MapperContext context)
        {
            var action = MapperBuilder <From, To> .ActionBuild(context.Setting);

            action(from, context, target);
            callBack?.Invoke(from, target);
            return(target);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 反射用到的,不能删
        /// </summary>
        public static void KeyValuePairLoadIntoCollection <TKey, TValue, FKey, FValue>(ICollection <KeyValuePair <TKey, TValue> > target, IEnumerable <KeyValuePair <FKey, FValue> > source, MapperContext context)
        {
            if (source.IsNullOrEmpty())
            {
                return;
            }

            foreach (var s in source)
            {
                var key   = EasyMapper.Map <FKey, TKey>(s.Key, null, context);
                var value = EasyMapper.Map <FValue, TValue>(s.Value, null, context);
                target.Add(new KeyValuePair <TKey, TValue>(key, value));
            }

            return;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 反射用到的,不能删
 /// </summary>
 public static T?ConvertToNullableValueFromValue <T, F>(F value, MapperContext context) where T : struct, IConvertible where F : struct, IConvertible
 {
     return(new T?(EasyMapper.Map <F, T>(value, null, context)));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 反射用到的,不能删
        /// </summary>
        public static void KeyValuePairLoadIntoDictionary <TKey, TValue, FKey, FValue>(IDictionary <TKey, TValue> target, IEnumerable <KeyValuePair <FKey, FValue> > source, MapperContext context)
        {
            if (source.IsNullOrEmpty())
            {
                return;
            }

            foreach (var s in source)
            {
                var key   = EasyMapper.Map <FKey, TKey>(s.Key, null, context);
                var value = EasyMapper.Map <FValue, TValue>(s.Value, null, context);
                target[key] = value;
            }

            return;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 反射用到的,不能删
        /// </summary>
        public static void LoadIntoCollection <T, F>(ICollection <T> target, IEnumerable <F> source, MapperContext context)
        {
            if (source.IsNullOrEmpty())
            {
                return;
            }

            foreach (var s in source)
            {
                target.Add(EasyMapper.Map <F, T>(s, null, context));
            }

            return;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 反射用到的,不能删
        /// </summary>
        public static void LoadIntoEnumerable <T, F>(IEnumerable <T> target, IEnumerable <F> source, MapperContext context)
        {
            if (source.IsNullOrEmpty())
            {
                return;
            }

            foreach (var s in source)
            {
                target = target.Union(new[] { EasyMapper.Map <F, T>(s, null, context) });
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 确定条数,反射用到的,不能删
 /// </summary>
 public static int MakeSureEnumerableCount <F>(IEnumerable <F> source, MapperContext context)
 {
     return(source == null ? 0 : source.Count());
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 枚举ToString,反射用到的,不能删
 /// </summary>
 private static string _GenericToString <T>(T @object, MapperContext context) where T : IConvertible
 {
     return(@object.ToString());
 }