日期:2014-05-17 浏览次数:20778 次
class TestAttributes
{
private string test;
[MyAttribute(My="变量信息")]
public string Test
{
get { return test; }
set { test = value; }
}
}
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
private string my;
/// <summary>
/// 实体实际对应的表名
/// </summary>
public string My
{
get { return my; }
set { my = value; }
}
}
Type tAb = typeof(TestAttributes);
foreach (System.Reflection.PropertyInfo propInfo in tAb.GetProperties())
{
MessageBox.Show(propInfo.Name);
object[] testAb = propInfo.GetCustomAttributes(typeof(MyAttribute), true);
foreach (object cAb in testAb)
{
MessageBox.Show(cAb.ToString());
}
}