this.button1.Click += new System.EventHandler(this.button1_Click_2); //注册事件this.button1.Click-=new System.EventHandler(this.button1_Click_2); //取消注册
解决方案 »
- 求问一下Entity SQL或者Linq To Entity如何实现这个Oracle SQL语句
- 保存xml内容,不是保存.xml
- 数据库取值问题!
- 高手们帮忙,怎么在水晶报表中设置曲线图的数据.我用的是vs2008自带的cr.
- c# 怎样在一个from修改另一个没有实例化的from里面的值
- 如何实现mdi子窗体的位置固定不可改变
- panel的小问题
- 救急呀!!!!! vs2003 DataGrid问题
- 请帮我看看这段代码!很急!
- 我的Web页面中的DataGrid的数据绑定必须写在PreRender事件中, 但是这样不会保存Grid的状态(ViewState),请问该如何手动保存状态呢?
- 怎样把comboBox绑定到DataGrid中 谢谢
- 讨论:数据转换的技术解决方案
using System.IO;
using System.Reflection;class cAuthorAttribute:Attribute
{
public cAuthorAttribute(string name)
{
m_name=name;
}
public string Name
{
get
{
return m_name;
}
set
{
m_name=value;
}
} public string Note
{
get
{
return m_note;
}
set
{
m_note=value;
}
}
protected string m_name;
protected string m_note;
}[cAuthor("Xiongqin")]
class cMyClass
{
public cMyClass()
{ } [cAuthor("Xiongqin")]
public string Str()
{
return null;
} public int m_i; [cAuthor("Xiongqin")]
public float m_f;}class cAttributeTest
{
public cAttributeTest(Type theType)
{
m_type=theType;
}
public string GetAuthorName()
{
foreach(Attribute attrib in m_type.GetCustomAttributes(true))
{
cAuthorAttribute author_attrib=attrib as cAuthorAttribute;
if(author_attrib!=null)
return author_attrib.Name;
}
return null;
} public string GetNotes()
{
foreach(Attribute attrib in m_type.GetCustomAttributes(true))
{
cAuthorAttribute author_attrib=attrib as cAuthorAttribute;
if(author_attrib!=null)
return author_attrib.Note;
}
return null;
} public string[] GetAllMemberAutoInfo()
{
MemberInfo[] members=m_type.GetMembers();
string[] result=new string[members.Length]; int n=0;
foreach(MemberInfo meminfo in members)
{
string name=meminfo.Name;
string memberType=meminfo.MemberType.ToString();
string author=Member_Author(meminfo);
if(author==null)
author="Not Known";
result[n]=memberType+":"+name+",autor: "+author;
n++;
}
return result;
} public string[] GetMemberAuthorInof(string memberName)
{
MemberInfo[] members=m_type.GetMember(memberName);
string[] result=new string[members.Length];
int n=0;
foreach(MemberInfo meminfo in members)
{
string name=meminfo.Name;
string memberType=meminfo.MemberType.ToString();
string author=Member_Author(meminfo);
if(author==null)
author="Not Known";
result[n]=memberType+":"+name+",author: "+author;
}
return result;
} protected string Member_Author(MemberInfo meminfo)
{
foreach(Attribute attrib in meminfo.GetCustomAttributes(true))
{
cAuthorAttribute auth=attrib as cAuthorAttribute;
if(auth!=null)
return auth.Name;
}
return null;
} protected Type m_type;
}class cMyApp
{
public static int Main(string[] args)
{
cMyClass myclass=new cMyClass(); cAttributeTest attrib_test=new cAttributeTest(typeof(cMyClass)); Console.WriteLine(attrib_test.GetAuthorName());
foreach(string str in attrib_test.GetAllMemberAutoInfo())
Console.WriteLine(str); Console.WriteLine("***********************************************");
foreach(string str in attrib_test.GetMemberAuthorInof("m_f"))
{
Console.WriteLine(str);
}
// Console.WriteLine(attrib_test.GetAllMemberAutoInfo()[2]);
// Console.WriteLine(attrib_test.GetNotes());
return 0;
}
}
这段代码看明白了,特性如何用也就知道了