我不确定这是否是一般情况,但我认为是的。请尝试以下操作:
class Program
{
static void Main(string[] args)
{
// display the custom attributes on our method
Type t = typeof(Program);
foreach (object obj in t.GetMethod("Method").GetCustomAttributes(false))
{
Console.WriteLine(obj.GetType().ToString());
}
// display the custom attributes on our delegate
Action d = new Action(Method);
foreach (object obj in d.Method.GetCustomAttributes(false))
{
Console.WriteLine(obj.GetType().ToString());
}
}
[CustomAttr]
public static void Method()
{
}
}
public class CustomAttrAttribute : Attribute
{
}
Run Code Online (Sandbox Code Playgroud)