Example #1
0
    static void Main(string[] args)
    {
        // create an Attribute Tester for the attribute we are interested in
        AttributeTester <ObsoleteAttribute> attrTester = new AttributeTester <ObsoleteAttribute>();

        // check to see if the attribute has been applied to a property
        bool methodTest = attrTester.TestForMethodAttribute(typeof(Calculator), "CalculateProduct");

        Console.WriteLine("At least one overloaded method has attribute: {0}", methodTest);

        // get a list of the names of the properties that have been modified
        string[] modifiedMethods = attrTester.GetModifiedMethodNames(typeof(Calculator));
        foreach (string s in modifiedMethods)
        {
            Console.WriteLine("Modified method: {0}", s);
        }

        // get a series of structs representing modified methods and their attributes
        MethodAttributePair <ObsoleteAttribute>[] mods = attrTester.GetModifiedMethods(typeof(Calculator));
        foreach (MethodAttributePair <ObsoleteAttribute> mp in mods)
        {
            Console.WriteLine("--- Method with Obsolete Attribute ---");
            Console.WriteLine("Method signature: {0}", mp.MethodSignature);
            Console.WriteLine("Attribute message: {0}", mp.Attribute.Message);
            Console.WriteLine("Attribute error: {0}", mp.Attribute.IsError);
        }

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }