Ejemplo n.º 1
0
 /// <summary>
 /// 将当前对象的属性值复制到目标对象,使用浅表复制
 /// </summary>
 /// <typeparam name="T">目标对象类型</typeparam>
 /// <param name="source">源对象</param>
 /// <param name="target">目标对象,如果为空,将生成一个</param>
 /// <returns>复制过后的目标对象</returns>
 public static T CopyTo <T>(this object source, T target = null) where T : class, new()
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         target = new T();
     }
     ModuleCast.GetCast(source.GetType(), typeof(T)).Cast(source, target);
     return(target);
 }
Ejemplo n.º 2
0
 /// <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
 {
     ModuleCast.GetCast(typeof(TSource), typeof(TTarget)).Cast(source, target);
 }