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;
}