获取附加在方法上的Attribute

如下:

class Program
{
    static void Main(string[] args)
    {
        var methodInfo = typeof(Program).GetMethod("Function");
        var a = methodInfo.CustomAttributes.First(w => w.AttributeType == typeof(BrowsableAttribute));
        var b = (bool)(a.ConstructorArguments.First().Value);
        Console.Read();
    }
    [Browsable(false)]
    public void Function()
    {

    }
}

 

posted on 2013-08-04 20:53  yao2yao4  阅读(258)  评论(0编辑  收藏  举报

导航