通过反射获得TableAttribute
2017-10-14 23:49:58 访问(1778) 赞(0) 踩(0)
Type curType = this.GetType();
// 转义逻辑类 //
// 获得TableAttribute的逻辑类 //
// 旧版本代码模式下 //
// TableAttribute 和 Business 在同一个dll里面 //
// 返回值:如:SlowX.UserLib.TableAttribute.UTB_SLOWX_USER_ITEM //
string btaClassName = curType.FullName.Replace(".Business.", ".TableAttribute.");
Assembly ass = curType.Assembly;
Type tbType = ass.GetType(btaClassName, false, true);
if (tbType == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ btaClassName + "没有获得对应的BaseTableAttribute"
);
}
FieldInfo fi = tbType.GetField("instance", BindingFlags.Static | BindingFlags.Public);
if (fi == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ btaClassName + "没有获得对应的BaseTableAttribute"
);
}
BaseTableAttribute theResult =
fi.GetValue(null) as BaseTableAttribute;
if (theResult == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ btaClassName + "没有获得对应的BaseTableAttribute"
);
}
return theResult;
上一条:
下一条:
相关评论
发表评论