首次提交:添加src文件夹代码
This commit is contained in:
76
Cowain.Bake.Common/Core/BasicFramework.cs
Normal file
76
Cowain.Bake.Common/Core/BasicFramework.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
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.Bake.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BasicFramework()
|
||||
{
|
||||
SetRegularDic();
|
||||
}
|
||||
|
||||
private void SetRegularDic()
|
||||
{
|
||||
RegularDic.Clear();
|
||||
RegularDic.Add("decimal2", "^([1-9]+[\\d]*(.[0-9]{1,2})?)$");
|
||||
RegularDic.Add("Int32", @"^(0|-?[1-9]\d*)$");// "^[0-9]*$");
|
||||
RegularDic.Add("Int16", "^([1-9](\\d{0,3}))$|^([1-5]\\d{4})$|^(6[0-4]\\d{3})$|^(65[0-4]\\d{2})$|^(655[0-2]\\d)$|^(6553[0-5])$");
|
||||
RegularDic.Add("bool", "^[01]$");
|
||||
RegularDic.Add("Float", @"^(?!\.?$)\d+(\.\d+)?([eE][-+]?\d+)?$");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user