通过反射获得逻辑类的属性设置(方便下次刷代码时候的效率)
2017-10-05 15:12:46 访问(1390) 赞(0) 踩(0)
-
逻辑代码
/// <summary>
///
/// </summary>
/// <param name="t"></param>
/// <param name="tb"></param>
/// <returns></returns>
public bool IsBaseType(Type t, Type tb)
{
if (t == null)
return false;
while (true)
{
if (t == tb)
return true;
t = t.BaseType;
if (t == null)
return false;
}
}
protected void ToResult()
{
Assembly ass = typeof(eKing.XlyLib.Helpers.eKingXlyLibHelper).Assembly;
Type tB = typeof(SlowX.Core.Business.BaseBusiness);
Type[] tA = ass.GetTypes();
StringBuilder theResult = new StringBuilder();
int idx = 0;
string FullClassName = null;
string TableName = null;
string SubLibName = null;
string RootLibName = null;
int subLen = ("eKing.XlyLib.Business.").Length;
foreach (Type t in tA)
{
if (!IsBaseType(t, tB))
continue;
FullClassName = t.FullName;
idx = FullClassName.LastIndexOf('.');
TableName = FullClassName.Substring(idx + 1);
RootLibName = "eKing.Xly{0}";
SubLibName = FullClassName.Substring(0, idx);
if (SubLibName == "eKing.XlyLib.Business")
SubLibName = "";
else
SubLibName = SubLibName.Substring(subLen);
theResult.AppendLine(@"
#region " + TableName + @"
item = new HisCreateLibItem();
item.FullClassName = """ + FullClassName + @""";
item.RootLibName = """ + RootLibName + @""";
item.SubLibName = """ + SubLibName + @""";
item.TableName = """ + TableName + @""";
theResult.Add(item);
#endregion " + TableName + @"
");
}
TextBox1.Text =
@"
#region 添加
" +
theResult.ToString() + @"
#endregion 添加
";
}
HisCreateLibItem
using System;
using System.Collections.Generic;
using System.Text;
namespace SlowX.CreateLibApp.Classes.HisCreateLibs
{
/// <summary>
/// 组名·通过这个重建逻辑类
/// </summary>
[Serializable]
public partial class HisCreateLibItem
{
/// <summary>
///
/// </summary>
public HisCreateLibItem()
{
}
#region RootLibName ~ 根逻辑类
/// <summary>
/// RootLibName ~ 根逻辑类
/// </summary>
protected string m_RootLibName = null;
/// <summary>
/// RootLibName ~ 根逻辑类
/// </summary>
public string RootLibName
{
get
{
return m_RootLibName;
}
set
{
m_RootLibName = value;
}
}
#endregion RootLibName ~ 根逻辑类
#region SubLibName ~ 子逻辑类
/// <summary>
/// SubLibName ~ 子逻辑类
/// </summary>
protected string m_SubLibName = null;
/// <summary>
/// SubLibName ~ 子逻辑类
/// </summary>
public string SubLibName
{
get
{
return m_SubLibName;
}
set
{
m_SubLibName = value;
}
}
#endregion SubLibName ~ 子逻辑类
#region TableName ~ 表名
/// <summary>
/// TableName ~ 表名
/// </summary>
protected string m_TableName = null;
/// <summary>
/// TableName ~ 表名
/// </summary>
public string TableName
{
get
{
return m_TableName;
}
set
{
m_TableName = value;
}
}
#endregion TableName ~ 表名
#region FullClassName ~ 完整路径
/// <summary>
/// FullClassName ~ 完整路径
/// </summary>
protected string m_FullClassName = null;
/// <summary>
/// FullClassName ~ 完整路径
/// </summary>
public string FullClassName
{
get
{
return m_FullClassName;
}
set
{
m_FullClassName = value;
}
}
#endregion FullClassName ~ 完整路径
public static List<HisCreateLibItem> HisCreateLibItemList(SlowX.CreateLibApp.Enums.HisCreateLib.EmHisCreateLib em)
{
switch (em)
{
case SlowX.CreateLibApp.Enums.HisCreateLib.EmHisCreateLib.eKingXlyLib:
return eKingXlyLib();
}
return null;
}
}
}
eKingXlyLib空方法
using System;
using System.Collections.Generic;
using System.Text;
namespace SlowX.CreateLibApp.Classes.HisCreateLibs
{
public partial class HisCreateLibItem
{
/// <summary>
///
/// </summary>
/// <returns></returns>
protected static List<HisCreateLibItem> eKingXlyLib()
{
List<HisCreateLibItem> theResult = new List<HisCreateLibItem>();
HisCreateLibItem item = null;
#region 添加
#endregion 添加
return theResult;
}
}
}
-
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="100%" Height="500px"></asp:TextBox>
</div>
</form>
</body>
</html>
上一条:
下一条:
相关评论
发表评论