12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using AutoMapper;
- using AutoMapper.Mappers;
- namespace Bowin.Common.Mapping
- {
- public static class MappingExtensions
- {
- public static T CloneTo<T>(this T obj, T newObj)
- {
- Mapper.CreateMap<T, T>();
- Mapper.DynamicMap<T, T>(obj, newObj);
- return newObj;
- }
- public static void DynamicCloneTo<TSource, TDestination>(this TSource source, TDestination destination)
- {
- Mapper.DynamicMap(source,destination);
- }
- public static T To<T, TType>(this IEnumerable<TType> objects) where T : IList<TType>, new()
- {
- if (objects == null) return default(T);
- var tResult = new T();
- foreach (var s in objects) tResult.Add(s);
- return tResult;
- }
- }
- }
|