public static class MapperExtensions { public static TResult MapTo(this object self, TResult result) { if (self == null) throw new ArgumentNullException(); Mapper.CreateMap(self.GetType().UnderlyingSystemType, typeof(TResult)); return (TResult)Mapper.Map(self, result, self.GetType(), typeof(TResult)); } }
调用
f.MapTo(Entity);//f源 Entity目标