62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Cowain.Preheat.Common.Core
|
|
{
|
|
public class BasicFramework
|
|
{
|
|
private static BasicFramework instance;
|
|
private static readonly object locker = new object();
|
|
public Dictionary<string, string> RegularDic = new Dictionary<string, string>();
|
|
public static BasicFramework Instance
|
|
{
|
|
get
|
|
{
|
|
lock (locker)
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = new BasicFramework();
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
}
|
|
public static T DeepCopy<T>(T obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return obj;
|
|
}
|
|
if (obj is string || obj.GetType().IsValueType)
|
|
return obj;
|
|
|
|
object retval = Activator.CreateInstance(obj.GetType());
|
|
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
|
|
foreach (var field in fields)
|
|
{
|
|
try
|
|
{
|
|
field.SetValue(retval, DeepCopy(field.GetValue(obj)));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.GetCurrentClassError((typeof(BasicFramework) + "DeepCopy异常:" + ex.Message));
|
|
}
|
|
}
|
|
|
|
return (T)retval;
|
|
}
|
|
|
|
|
|
}
|
|
}
|