-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVPExtensions.cs
43 lines (42 loc) · 1.29 KB
/
VPExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Reflection;
using UnityEngine;
namespace VanillaPlus
{
public static class VPExtensions
{
public static T DeepCopyOf<T>(this T self, T from) where T : class
{
FieldInfo[] fields = typeof(T).GetFields((BindingFlags)(-1));
FieldInfo[] array = fields;
foreach (FieldInfo fieldInfo in array)
{
try
{
fieldInfo.SetValue(self, fieldInfo.GetValue(from));
}
catch
{
Debug.Log("you suck and you field");
}
}
PropertyInfo[] properties = typeof(T).GetProperties((BindingFlags)(-1));
PropertyInfo[] array3 = properties;
foreach (PropertyInfo propertyInfo in array3)
{
bool flag = propertyInfo.CanWrite && propertyInfo.CanRead;
if (flag)
{
try
{
propertyInfo.SetValue(self, propertyInfo.GetValue(from));
}
catch
{
Debug.Log("you suck and you property");
}
}
}
return self;
}
}
}