class a
{
private String name; [MyAttribute]
public String Name{get{}set{}} private int age; [AnotherAttribute]
public int Age{get{}set{}}
}
Type t = a.GetType();forea(PropertyInfo p in t.GetProperties)
{
p.////如何获取p的attribute,并且判断是MyAttribute还是AnotherAttribute?
}
{
private String name; [MyAttribute]
public String Name{get{}set{}} private int age; [AnotherAttribute]
public int Age{get{}set{}}
}
Type t = a.GetType();forea(PropertyInfo p in t.GetProperties)
{
p.////如何获取p的attribute,并且判断是MyAttribute还是AnotherAttribute?
}
解决方案 »
- dataGridView 的columnType设为DataGridViewCheckBoxColumn的列为何不能自动排序
- 求算法
- 货币格式应该怎么做乘除加减法
- 想用c#编写串口,不知用哪种方法好?(初学者)
- 操作EXCEL时出现的错误,“外部表不是预期的格式。”
- 请教大家一个基础问题:在属性定义的前面加上[DataMember]是什么意思呢?
- c#中backgroundwoker在打印時的使用問題
- C#中调用Api的问题
- 为什么C#中,把控件的enable设成false或把它的readonly设成true,怎么都是灰色的了。
- 怎样使用compact framework 下的pocket pc 的simulation
- 新手问题-关于ComboText用户输入的问题
- 新手的两个小问题,马上结帐
{
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.PropertyInfo");
// Define a property.
Myproperty Myproperty = new Myproperty();
Console.Write("\nMyproperty.Caption = " + Myproperty.Caption);
// Get the type and PropertyInfo.
Type MyType = Type.GetType("Myproperty");
PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption");
// Get and display the attributes property.
PropertyAttributes Myattributes = Mypropertyinfo.Attributes;
Console.Write("\nPropertyAttributes - " + Myattributes.ToString());
return 0;
}
}