|
@@ -1,9 +1,11 @@
|
|
using JLHHJSvr.LJException;
|
|
using JLHHJSvr.LJException;
|
|
using System;
|
|
using System;
|
|
using System.Data.SqlClient;
|
|
using System.Data.SqlClient;
|
|
|
|
+using System.Data.SqlTypes;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
+using System.Web.UI.WebControls;
|
|
|
|
|
|
namespace JLHHJSvr.Tools
|
|
namespace JLHHJSvr.Tools
|
|
{
|
|
{
|
|
@@ -51,5 +53,38 @@ namespace JLHHJSvr.Tools
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static void AutoInitS<T>(T instance)
|
|
|
|
+ {
|
|
|
|
+ foreach (var TB in instance.GetType().GetProperties())
|
|
|
|
+ {
|
|
|
|
+ var type = TB.PropertyType;
|
|
|
|
+
|
|
|
|
+ var value = TB.GetValue(instance, null);
|
|
|
|
+ if (value == null)
|
|
|
|
+ {
|
|
|
|
+ if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
|
|
|
|
+ {
|
|
|
|
+ type = type.GetGenericArguments()[0];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type.IsAssignableFrom(typeof(string)))
|
|
|
|
+ {
|
|
|
|
+ value = string.Empty;
|
|
|
|
+ }
|
|
|
|
+ else if (type.IsAssignableFrom(typeof(int))
|
|
|
|
+ || type.IsAssignableFrom(typeof(decimal))
|
|
|
|
+ || type.IsAssignableFrom(typeof(byte)))
|
|
|
|
+ {
|
|
|
|
+ value = Activator.CreateInstance(type);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (value != null)
|
|
|
|
+ {
|
|
|
|
+ TB.SetValue(instance, value, null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|