XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
关注
0
Fork
0
Star
0
返回提交历史
Deleted
XFE各类拓展/ObjectExtention.cs
+0
-42
XFEstudio/XFEExtension
Delete XFE各类拓展/ObjectExtention.cs
b697b3f
代码差异
1 个文件
+0
-42
@@ -1,42 +0,0 @@
1
using System;
2
3
namespace XFE各类拓展.ObjectExtension
4
{
5
/// <summary>
6
/// 所有类的基类的拓展
7
/// </summary>
8
public static class ObjectExtension
9
{
10
/// <summary>
11
/// 进行浅拷贝
12
/// </summary>
13
/// <typeparam name="T"></typeparam>
14
/// <param name="source"></param>
15
/// <returns>浅拷贝后的对象</returns>
16
/// <exception cref="ArgumentNullException">无类型错误</exception>
17
public static T ActiveCopyOf<T>(this T source) where T : class
18
{
19
if (source == null)
20
{
21
throw new ArgumentNullException(nameof(source));
22
}
23
return (T)source.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(source, null);
24
}
25
/// <summary>
26
/// 进行静态拷贝
27
/// </summary>
28
/// <typeparam name="T"></typeparam>
29
/// <param name="source"></param>
30
/// <returns>静态拷贝后的对象</returns>
31
public static T StaticCopyOf<T>(this T source) where T : class, new()
32
{
33
var properties = typeof(T).GetProperties();
34
var newObject = new T();
35
foreach (var property in properties)
36
{
37
property.SetValue(newObject, property.GetValue(source));
38
}
39
return newObject;
40
}
41
}
42
}