You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.4 KiB
141 lines
3.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace OT.COM.ArsenalDB
|
|
{
|
|
public class EntityUtil
|
|
{
|
|
public static DBColumnInfo GetDBColumnInfo(Type i_tTable, string i_sColumnName)
|
|
{
|
|
DBColumnInfo dbiRes = null;
|
|
|
|
do
|
|
{
|
|
PropertyInfo pi = i_tTable.GetProperty(i_sColumnName.ToLower());
|
|
|
|
if (pi == null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
System.Attribute attr = System.Attribute.GetCustomAttribute(pi, typeof(ColumnMiscAttribute));
|
|
|
|
if (attr == null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
ColumnMiscAttribute cma = attr as ColumnMiscAttribute;
|
|
DBColumnInfo dbi = cma.Data;
|
|
|
|
dbiRes = dbi;
|
|
}
|
|
while (false);
|
|
|
|
return dbiRes;
|
|
}
|
|
|
|
public static bool ColumnIsPaddingStringType(Type i_tTable, string i_sColumnName)
|
|
{
|
|
bool bRes = false;
|
|
|
|
DBColumnInfo dbi = GetDBColumnInfo(i_tTable, i_sColumnName);
|
|
|
|
if (dbi != null)
|
|
{
|
|
string sType = dbi.DATA_TYPE.ToLower();
|
|
bRes = sType == "char" || sType == "nchar";
|
|
}
|
|
|
|
return bRes;
|
|
}
|
|
|
|
public static bool ColumnSupportNull(Type i_tTable, string i_sColumnName)
|
|
{
|
|
bool bRes = false;
|
|
|
|
DBColumnInfo dbi = GetDBColumnInfo(i_tTable, i_sColumnName);
|
|
|
|
if(dbi != null)
|
|
{
|
|
bRes = dbi.IsNullable;
|
|
}
|
|
|
|
return bRes;
|
|
}
|
|
|
|
|
|
public static string Removepadding(string i_sOri, string i_sColumnName, Type i_tTable)
|
|
{
|
|
string sRes = null;
|
|
|
|
do
|
|
{
|
|
if (i_sOri == null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
PropertyInfo pi = i_tTable.GetProperty(i_sColumnName.ToLower());
|
|
if (pi == null)
|
|
{
|
|
break;
|
|
}
|
|
ColumnMiscAttribute cma = EntityUtil.GetPropertyAttribute<ColumnMiscAttribute>(pi);
|
|
|
|
if (cma == null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
string sType = cma.Data.DATA_TYPE.ToLower();
|
|
|
|
if (sType == "char" || sType == "nchar")
|
|
{
|
|
string s = i_sOri.ToString();
|
|
|
|
s = s.TrimEnd();
|
|
sRes = s;
|
|
}
|
|
|
|
}
|
|
while (false);
|
|
|
|
|
|
if (sRes == null)
|
|
{
|
|
sRes = i_sOri;
|
|
}
|
|
|
|
return sRes;
|
|
}
|
|
public static T GetPropertyAttribute<T>(PropertyInfo i_tTest) where T : class
|
|
{
|
|
object[] oa = i_tTest.GetCustomAttributes(typeof(T), true);
|
|
T tRes = null;
|
|
|
|
if (oa != null && oa.Length > 0)
|
|
{
|
|
tRes = oa[0] as T;
|
|
}
|
|
|
|
return tRes;
|
|
}
|
|
|
|
public static T GetClassAttribute<T>(Type i_tTest) where T : class
|
|
{
|
|
object[] oa = i_tTest.GetCustomAttributes(typeof(T), true);
|
|
T tRes = null;
|
|
|
|
if (oa != null && oa.Length > 0)
|
|
{
|
|
tRes = oa[0] as T;
|
|
}
|
|
|
|
return tRes;
|
|
}
|
|
}
|
|
}
|