这是我的程序
<code>
[demosapect]
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=xx;User ID=sa;");
</code>
我正在使用这些代码
foreach (FieldInfo targetfield in type.GetFields(BindingFlags.CreateInstance | BindingFlags.DeclaredOnly | BindingFlags.Default | BindingFlags.ExactBinding ))
{
// here i need to list out those attributes......
}
foreach (FieldInfo targetfield in type.GetFields(BindingFlags.CreateInstance | BindingFlags.DeclaredOnly | BindingFlags.Default | BindingFlags.ExactBinding ))
{
// here i need to list out those attributes......
}
我需要通过反射列出属性名称[demoaspect]!
等待你的回复......
答案 0 :(得分:0)
将此代码用作
if (targetfield.GetCustomAttributesData().Count > 0)
{
Console.WriteLine(targetfield.GetCustomAttributesData()[0].ToString());
}
if (targetfield.GetCustomAttributesData().Count > 0)
{
Console.WriteLine(targetfield.GetCustomAttributesData()[0].ToString());
}
它解决了我的疑问!!!!!!!!