懒得勤快 vor 7 Jahren
Ursprung
Commit
7878955fc7

+ 13 - 0
Masuit.Tools.Core/Extensions.cs

@@ -349,6 +349,19 @@ namespace Masuit.Tools
             return dest;
         }
 
+        /// <summary>
+        /// 复制到一个现有对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="source">源对象</param>
+        /// <param name="dest">目标对象</param>
+        /// <returns></returns>
+        public static T CopyTo<T>(this T source, T dest) where T : new()
+        {
+            dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
+            return dest;
+        }
+
         /// <summary>
         /// 复制一个新的对象
         /// </summary>

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>1.8.5</Version>
+    <Version>1.8.6</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。

+ 13 - 0
Masuit.Tools/Extensions.cs

@@ -349,6 +349,19 @@ namespace Masuit.Tools
             return dest;
         }
 
+        /// <summary>
+        /// 复制到一个现有对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="source">源对象</param>
+        /// <param name="dest">目标对象</param>
+        /// <returns></returns>
+        public static T CopyTo<T>(this T source, T dest) where T : new()
+        {
+            dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
+            return dest;
+        }
+
         /// <summary>
         /// 复制一个新的对象
         /// </summary>

+ 2 - 2
Masuit.Tools/Properties/AssemblyInfo.cs

@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
 
-[assembly: AssemblyVersion("1.8.0")]
-[assembly: AssemblyFileVersion("1.8.0")]
+[assembly: AssemblyVersion("1.8.3")]
+[assembly: AssemblyFileVersion("1.8.3")]
 [assembly: NeutralResourcesLanguage("zh-CN")]
 

+ 28 - 3
Test/Program.cs

@@ -1,6 +1,7 @@
 using System;
-using Masuit.Tools.Models;
-using Masuit.Tools.Net;
+using System.Collections.Generic;
+using System.Linq;
+using Masuit.Tools;
 
 namespace Test
 {
@@ -44,9 +45,33 @@ namespace Test
             //Console.WriteLine(WindowsCommand.Execute("help"));
             //string match = "vawevbgw".MatchRandomImgSrc();
             //Console.WriteLine(match);
-            PhysicsAddress address = "4.2.2.1".GetPhysicsAddressInfo();
+            //PhysicsAddress address = "4.2.2.1".GetPhysicsAddressInfo();
+
+            List<MyClass> mc = new List<MyClass> { new MyClass() { Name = "aaa", Age = 10, MyClass3 = new MyClass3(), MyClass2s = new List<MyClass2>() { new MyClass2() { Age = 22, Name = "dddd" } } }, new MyClass() { Name = "aaa", Age = 10, MyClass3 = new MyClass3(), MyClass2s = new List<MyClass2>() { new MyClass2() { Age = 22, Name = "dddd" } } }, new MyClass() { Name = "aaa", Age = 10, MyClass3 = new MyClass3(), MyClass2s = new List<MyClass2>() { new MyClass2() { Age = 22, Name = "dddd" } } }, new MyClass() { Name = "aaa", Age = 10, MyClass3 = new MyClass3(), MyClass2s = new List<MyClass2>() { new MyClass2() { Age = 22, Name = "dddd" } } } };
+            List<MyClass2> list = mc.Map<MyClass, MyClass2>().ToList();
 
             Console.ReadKey();
         }
     }
+
+    public class MyClass
+    {
+        public string Name { get; set; }
+        public int Age { get; set; }
+        public MyClass3 MyClass3 { get; set; }
+        public List<MyClass2> MyClass2s { get; set; }
+    }
+
+    public class MyClass2
+    {
+        public string Name { get; set; }
+        public int Age { get; set; }
+
+    }
+
+    public class MyClass3
+    {
+        public string MyProperty { get; set; }
+
+    }
 }