|
@@ -8,6 +8,7 @@ using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Runtime.InteropServices;
|
|
|
+using System.Runtime.Serialization.Formatters.Binary;
|
|
|
using System.Text;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
@@ -538,6 +539,55 @@ namespace PDF_Master.Helper
|
|
|
return text;
|
|
|
}
|
|
|
catch { return ""; }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 深拷贝方法 解决全局的静态右键菜单问题
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="T"></typeparam>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static T DeepClone<T>(T obj)
|
|
|
+ {
|
|
|
+ if (obj == null)
|
|
|
+ {
|
|
|
+ return default(T);
|
|
|
+ }
|
|
|
+
|
|
|
+ var objType = obj.GetType();
|
|
|
+ if (objType.IsValueType || objType == typeof(string))
|
|
|
+ {
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建新实例
|
|
|
+ T newObj = (T)Activator.CreateInstance(objType);
|
|
|
+
|
|
|
+ // 递归复制属性
|
|
|
+ PropertyInfo[] properties = objType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|
|
+ foreach (PropertyInfo property in properties)
|
|
|
+ {
|
|
|
+ if (!property.CanWrite || !property.CanRead)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 如果属性是引用类型,继续拷贝
|
|
|
+ var propertyType = property.PropertyType;
|
|
|
+ if (propertyType.IsClass && propertyType != typeof(string))
|
|
|
+ {
|
|
|
+ var propertyValue = property.GetValue(obj, null);
|
|
|
+ var propertyValueClone = DeepClone(propertyValue);
|
|
|
+ property.SetValue(newObj, propertyValueClone, null);
|
|
|
+ }
|
|
|
+ // 否则直接赋值
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var propertyValue = property.GetValue(obj, null);
|
|
|
+ property.SetValue(newObj, propertyValue, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return newObj;
|
|
|
}
|
|
|
}
|
|
|
}
|