public class AuthorInfoAttribute : System.Attribute
{
public string m_Name;
public string m_Pname;
public string m_Type;
}
public class AuthorInfoClass
{
[AuthorInfo(m_Name = "用户信息表")]
public class UserInfo
{
private string user_Id;
private string user_Name;
private string user_Sex;
private string user_Department;
[AuthorInfo(m_Name = "帐号", m_Pname = "User_ID", m_Type = "varchar(20)")]
public string User_Id
{
get { return user_Id; }
set { user_Id = value; }
}
[AuthorInfo(m_Name = "姓名", m_Pname = "User_NAME", m_Type = "varchar(10)")]
public string User_Name
{
get { return user_Name; }
set { user_Name = value; }
}
[AuthorInfo(m_Name = "性别", m_Pname = "User_SEX", m_Type = "varchar(4)")]
public string User_Sex
{
get { return user_Sex; }
set { user_Sex = value; }
}
[AuthorInfo(m_Name = "部门", m_Pname = "User_DEPARTMENT", m_Type = "varchar(4)")]
public string User_Department
{
get { return user_Department; }
set { user_Department = value; }
}
}
[AuthorInfo(m_Name = "管理员认证表")]
public class AdministerInfo
{
private string uid;
private string ip;
private string dateline;
private string errorcount;
[AuthorInfo(m_Name = "会员ID", m_Pname = "Admin_ID", m_Type = "mediumint")]
public string Uid
{
get { return uid; }
set { uid = value; }
}
[AuthorInfo(m_Name = "IP地址", m_Pname = "Admin_IP", m_Type = "char")]
public string Ip
{
get { return ip; }
set { ip = value; }
}
[AuthorInfo(m_Name = "登录时间", m_Pname = "Admin_Date", m_Type = "DateTime")]
public string Dateline
{
get { return dateline; }
set { dateline = value; }
}
[AuthorInfo(m_Name = "错误次数", m_Pname = "Admin_mistake", m_Type = "tinyint")]
public string Errorcount
{
get { return errorcount; }
set { errorcount = value; }
}
}
[AuthorInfo(m_Name = "公告表")]
public class NoticeInfo
{
private string id;
private string author;
private string subject;
private string redirect;
private string displayorder;
[AuthorInfo(m_Name = "公告ID", m_Pname = "Notice_ID", m_Type = "varchar(20)")]
public string Id
{
get { return id; }
set { id = value; }
}
[AuthorInfo(m_Name = "作者姓名", m_Pname = "Notice_author", m_Type = "varchar(20)")]
public string Author
{
get { return author; }
set { author = value; }
}
[AuthorInfo(m_Name = "标题", m_Pname = "Notice_subject", m_Type = "varchar(40)")]
public string Subject
{
get { return subject; }
set { subject = value; }
}
[AuthorInfo(m_Name = "外部URL", m_Pname = "Notice_URL", m_Type = "varchar(100)")]
public string Redirect
{
get { return redirect; }
set { redirect = value; }
}
[AuthorInfo(m_Name = "显示顺序", m_Pname = "Notice_Order", m_Type = "tinyint")]
public string Displayorder
{
get { return displayorder; }
set { displayorder = value; }
}
}
[AuthorInfo(m_Name = "附件类型表")]
public class AnnexInfo
{
private string id;
private string extension;
private string maxsize;
[AuthorInfo(m_Name = "类型ID", m_Pname = "Annex_ID", m_Type = "tinyint")]
public string Id
{
get { return id; }
set { id = value; }
}
[AuthorInfo(m_Name = "扩展名", m_Pname = "Annex_Extension ", m_Type = "tinyint")]
public string Extension
{
get { return extension; }
set { extension = value; }
}
[AuthorInfo(m_Name = "允许上传最大值", m_Pname = "Annex_Max", m_Type = "tinyint")]
public string Maxsize
{
get { return maxsize; }
set { maxsize = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AuthorInfo;
using System.Reflection;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
TreeNode m_Node;
TreeNode t_Node;
TreeNode c_Node;
AuthorInfoAttribute m_Attribute;
public Form1()
{
InitializeComponent();
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Tag is AuthorInfoAttribute)
{
this.listView1.Items.Clear();
m_Attribute = (AuthorInfoAttribute)e.Node.Tag;
ListViewItem item = new ListViewItem(m_Attribute.m_Name);
item.SubItems.Add(m_Attribute.m_Pname);
item.SubItems.Add(m_Attribute.m_Type);
this.listView1.Items.Add(item);
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text= openFileDialog1.FileName;
string s=System.IO.Path.GetExtension(openFileDialog1.FileName);
if (s.Equals(".dll") || s.Equals(".exe"))
{
treeView1.Nodes.Clear();
ShowTreeView(textBox1.Text.Trim());
}
else
{
MessageBox.Show("请加载有效文件,或查看帮助");
}
}
}
private void ShowTreeView(string str)
{
Assembly asm = Assembly.LoadFrom(str);
Type[] type = asm.GetTypes();
foreach (Type temp in type)
{
AuthorInfoAttribute[] attributes = (AuthorInfoAttribute[])temp.GetCustomAttributes(typeof(AuthorInfoAttribute), false);
foreach (AuthorInfoAttribute tempAttribute in attributes)
{
m_Node = new TreeNode(tempAttribute.m_Name.ToString());
t_Node = new TreeNode("属性");
}
PropertyInfo[] myType = temp.GetProperties();
foreach (PropertyInfo property in myType)
{
AuthorInfoAttribute[] p_Attributes = (AuthorInfoAttribute[])property.GetCustomAttributes(typeof(AuthorInfoAttribute), false);
foreach (AuthorInfoAttribute p in p_Attributes)
{
c_Node = new TreeNode(p.m_Name.ToString());
c_Node.Tag = p;
t_Node.Nodes.Add(c_Node);
}
}
if (t_Node != null)
{
m_Node.Nodes.Add(t_Node);
}
if (m_Node != null)
{
this.treeView1.Nodes.Add(m_Node);
m_Node = null;
t_Node = null;
}
}
}
}
}