Пример #1
0
        public TToDictionary Map(TFromDictionary from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var keyMapper   = resolver.GetMapperWithVerify <TFromKey, TToKey>();
            var valueMapper = resolver.GetMapperWithVerify <TFromValue, TToValue>();

            var builder = Create(from);

            using (var e = GetSourceEnumerator(from))
            {
                var index = 0;
                while (e.MoveNext())
                {
                    var key   = keyMapper.Map(e.Current.Key, resolver);
                    var value = valueMapper.Map(e.Current.Value, resolver);
                    Add(ref builder, index, key, value);
                    index++;
                }
            }

            return(Complete(ref builder));
        }
Пример #2
0
        public KeyValuePair <UKey, UValue> Map(KeyValuePair <TKey, TValue> from, IObjectMapperResolver resolver)
        {
            var keyMapper   = resolver.GetMapperWithVerify <TKey, UKey>();
            var valueMapper = resolver.GetMapperWithVerify <TValue, UValue>();

            return(new KeyValuePair <UKey, UValue>(keyMapper.Map(from.Key, resolver), valueMapper.Map(from.Value, resolver)));
        }
Пример #3
0
        public TTo[,,,] Map(TFrom[,,,] from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();

            var iLen = from.GetLength(0);
            var jLen = from.GetLength(1);
            var kLen = from.GetLength(2);
            var lLen = from.GetLength(3);

            var to = new TTo[iLen, jLen, kLen, lLen];

            for (int i = 0; i < iLen; i++)
            {
                for (int j = 0; j < jLen; j++)
                {
                    for (int k = 0; k < kLen; k++)
                    {
                        for (int l = 0; l < lLen; l++)
                        {
                            to[i, j, k, l] = mapper.Map(from[i, j, k, l], resolver);
                        }
                    }
                }
            }

            return(to);
        }
Пример #4
0
        public ValueTask <U> Map(ValueTask <T> from, IObjectMapperResolver resolver)
        {
            var mapper = resolver.GetMapperWithVerify <T, U>();
            var to     = mapper.Map(from.Result, resolver); // task wait...!

            return(new ValueTask <U>(to));
        }
Пример #5
0
        public TToCollection Map(TFromCollection from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <TFromElement, TToElement>();

            var count   = from.FastCount();
            var builder = Create(count);

            using (var e = GetSourceEnumerator(from))
            {
                var index = 0;
                while (e.MoveNext())
                {
                    var value = mapper.Map(e.Current, resolver);
                    Add(ref builder, index, value);
                    index++;
                }
            }

            return(Complete(ref builder));
        }
Пример #6
0
        public Tuple <U1> Map(Tuple <T1> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            return(new Tuple <U1>(
                       resolver.GetMapperWithVerify <T1, U1>().Map(from.Item1, resolver)));
        }
Пример #7
0
        public IGrouping <TToKey, TToElement> Map(IGrouping <TFromKey, TFromElement> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var keyMapper     = resolver.GetMapperWithVerify <TFromKey, TToKey>();
            var elementMapper = resolver.GetMapperWithVerify <TFromElement, TToElement>();

            var key    = keyMapper.Map(from.Key, resolver);
            var values = new ArrayBuffer <TToElement>(from.FastCount() ?? 4);

            foreach (var item in from)
            {
                values.Add(elementMapper.Map(item, resolver));
            }

            return(new Grouping <TToKey, TToElement>(key, values.ToArray()));
        }
Пример #8
0
        public IList Map(TFromCollection from, IObjectMapperResolver resolver)
        {
            var mapper = resolver.GetMapperWithVerify <object, object>();
            var list   = new List <object>();

            foreach (var item in from)
            {
                list.Add(mapper.Map(item, resolver));
            }
            return(list);
        }
Пример #9
0
        public ExpandoObject Map(ExpandoObject from, IObjectMapperResolver resolver)
        {
            var objectMapper = resolver.GetMapperWithVerify <object, object>();

            var to = (IDictionary <string, object>) new ExpandoObject();

            foreach (var item in from)
            {
                to.Add(item.Key, objectMapper.Map(item.Value, resolver));
            }
            return((ExpandoObject)to);
        }
Пример #10
0
        public Lazy <U> Map(Lazy <T> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <T, U>();
            var to     = mapper.Map(from.Value, resolver);

            return(new Lazy <U>(to.AsFunc()));
        }
Пример #11
0
        public Task <U> Map(Task <T> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <T, U>();
            var to     = mapper.Map(from.Result, resolver); // task wait...!

            return(Task.FromResult(to));
        }
Пример #12
0
        public List <TTo> Map(List <TFrom> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();
            var list   = new List <TTo>(from.Count);

            foreach (var item in from)
            {
                list.Add(mapper.Map(item, resolver));
            }

            return(list);
        }
Пример #13
0
        public TTo[] Map(TFrom[] obj, IObjectMapperResolver resolver)
        {
            if (obj == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();

            var newArray = new TTo[obj.Length];

            for (int i = 0; i < obj.Length; i++)
            {
                newArray[i] = mapper.Map(obj[i], resolver);
            }

            return(newArray);
        }
Пример #14
0
        public ILookup <TToKey, TToElement> Map(ILookup <TFromKey, TFromElement> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var groupingMapper = resolver.GetMapperWithVerify <IGrouping <TFromKey, TFromElement>, IGrouping <TToKey, TToElement> >();

            var dict = new Dictionary <TToKey, IGrouping <TToKey, TToElement> >();

            foreach (var item in from)
            {
                var v = groupingMapper.Map(item, resolver);
                dict.Add(v.Key, v);
            }

            return(new Lookup <TToKey, TToElement>(dict));
        }
Пример #15
0
        public ArraySegment <TTo> Map(ArraySegment <TFrom> from, IObjectMapperResolver resolver)
        {
            if (from.Array == null)
            {
                return(new ArraySegment <TTo>(null, 0, 0));
            }

            var to     = new TTo[from.Count];
            var array  = from.Array;
            var max    = from.Offset + from.Count;
            var index  = 0;
            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();

            for (int i = from.Offset; i < max; i++)
            {
                to[index++] = mapper.Map(array[i], resolver);
            }

            return(new ArraySegment <TTo>(to));
        }
Пример #16
0
        public HashSet <TTo> Map(HashSet <TFrom> from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var comparer = useSameComparer
                ? (IEqualityComparer <TTo>)(object) from.Comparer
                : EqualityComparer;

            comparer = comparer ?? EqualityComparer <TTo> .Default;

            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();
            var to     = new HashSet <TTo>(comparer);

            foreach (var item in from)
            {
                to.Add(mapper.Map(item, resolver));
            }

            return(to);
        }
Пример #17
0
        public TTo[,] Map(TFrom[,] from, IObjectMapperResolver resolver)
        {
            if (from == null)
            {
                return(null);
            }

            var mapper = resolver.GetMapperWithVerify <TFrom, TTo>();

            var iLen = from.GetLength(0);
            var jLen = from.GetLength(1);

            var to = new TTo[iLen, jLen];

            for (int i = 0; i < iLen; i++)
            {
                for (int j = 0; j < jLen; j++)
                {
                    to[i, j] = mapper.Map(from[i, j], resolver);
                }
            }

            return(to);
        }
Пример #18
0
 public static T DeepCopy <T>(T cloneFrom, IObjectMapperResolver resolver)
 {
     return(resolver.GetMapperWithVerify <T, T>().Map(cloneFrom, resolver));
 }
Пример #19
0
 public static TTo Map <TFrom, TTo>(TFrom from, IObjectMapperResolver resolver)
 {
     return(resolver.GetMapperWithVerify <TFrom, TTo>().Map(from, resolver));
 }
Пример #20
0
 public IEnumerable <TTo> Map(IEnumerable <TFrom> obj, IObjectMapperResolver resolver)
 {
     return(resolver.GetMapperWithVerify <IEnumerable <TFrom>, TTo[]>().Map(obj, resolver));
 }
Пример #21
0
 public ValueTuple <U1> Map(ValueTuple <T1> from, IObjectMapperResolver resolver)
 {
     return(new ValueTuple <U1>(
                resolver.GetMapperWithVerify <T1, U1>().Map(from.Item1, resolver)));
 }