From 606469692e78a082de2d427aec3d856f2943d055 Mon Sep 17 00:00:00 2001 From: FalconFly <12919280+falconfly@user.noreply.gitee.com> Date: Tue, 18 Jul 2023 18:20:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=8Bclone?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi/ObjectExtend.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Falcon.SugarApi/ObjectExtend.cs b/Falcon.SugarApi/ObjectExtend.cs index 3480f7b..0b215db 100644 --- a/Falcon.SugarApi/ObjectExtend.cs +++ b/Falcon.SugarApi/ObjectExtend.cs @@ -20,14 +20,15 @@ namespace Falcon.SugarApi /// 原对象类型 /// 原对象 /// 目标对象 - public static TSource CloneTo(this TSource source,[NotNull] object target) where TSource : class { + /// 忽略大小写。默认false不忽略大小写 + public static TSource CloneTo(this TSource source,[NotNull] object target,bool ignoreCase = false) where TSource : class { _ = source ?? throw new ArgumentNullException(nameof(source)); _ = target ?? throw new ArgumentNullException(nameof(target)); var all = from s in source.GetType().GetProperties() - join t in target.GetType().GetProperties() on s.Name equals t.Name + join t in target.GetType().GetProperties() + on ignoreCase ? s.Name.ToLower() : s.Name equals ignoreCase ? t.Name.ToLower() : t.Name select new { s,t }; foreach(var item in all) { - //item.t.SetValue(target, Convert.ChangeType(item.s.getValue(source), item.t.Type)); item.t.SetValue(target,item.s.GetValue(source).ChangeType(item.t.PropertyType)); } return source; @@ -39,9 +40,10 @@ namespace Falcon.SugarApi /// 目标对象类型 /// 目标对象 /// 原对象 + /// 忽略大小写。默认false不忽略大小写 /// 目标对象 - public static Ttarget CloneFrom(this Ttarget target,object source) where Ttarget : class { - source.CloneTo(target); + public static Ttarget CloneFrom(this Ttarget target,object source,bool ignoreCase = false) where Ttarget : class { + source.CloneTo(target,ignoreCase); return target; }