📄 class1.cs
字号:
using System;
using System.Reflection;
namespace AttribIdentifiers
{
public class HRESULTAttribute : Attribute
{
public HRESULTAttribute()
{
}
}
class SomeClass
{
[method: HRESULT]
public long Foo() { return 0; }
[return: HRESULT]
public long Bar() { return 0; }
[property: HRESULT]
public long Goo { get { return 12345; } }
}
class Test
{
[STAThread]
static void Main(string[] args)
{
Type type =
Type.GetType("AttribIdentifiers.SomeClass");
foreach (MethodInfo m in type.GetMethods())
{
foreach (Attribute a in
m.GetCustomAttributes(true))
{
if (a is HRESULTAttribute)
{
Console.WriteLine(
"method: {0}, "
+ "CustomAttributes: {1}",
m.Name, a);
}
}
ICustomAttributeProvider icap =
m.ReturnTypeCustomAttributes;
foreach (Attribute a in
icap.GetCustomAttributes(true))
{
Console.WriteLine(
"method: {0}, "
+ "ReturnTypeCustomAttribs: {1}",
m.Name, a);
}
}
foreach (MemberInfo m in type.GetProperties())
{
foreach (Attribute a in
m.GetCustomAttributes(true))
{
Console.WriteLine(
"property: {0}, "
+ "CustomAttributes: {1}",
m.Name, a);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -