获取附加在方法上的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()

    {



    }

}

 

你可能感兴趣的:(attribute)