/// <summary> /// 拷贝当前对象的属性值到目标对象上 /// </summary> /// <typeparam name="T">目标对象类型</typeparam> /// <param name="source">当前对象</param> /// <returns>返回赋值过后的目标对象</returns> public static T CopyTo <T>(this object source) where T : class, new() { if (source == null) { throw new ArgumentNullException("source"); } T target = new T(); ModelCast.GetCast(source.GetType(), typeof(T)).Cast(source, target); return(target); }
/// <summary> /// 转换对象 /// </summary> /// <typeparam name="TSource">源类型</typeparam> /// <typeparam name="TTarget">目标类型</typeparam> /// <param name="source">源对象</param> /// <param name="target">目标对象</param> public static void CastObject <TSource, TTarget>(TSource source, TTarget target) where TSource : class where TTarget : class { ModelCast.GetCast(typeof(TSource), typeof(TTarget)).Cast(source, target); }