Beispiel #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 field
        bool fieldTest = attrTester.TestForFieldAttribute(typeof(Calculator), "MultiplierField");

        if (fieldTest)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetFieldAttribute(typeof(Calculator), "MultiplierField");
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

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



        // perform the same test, this time using a calc object

        // create an instance of the Calculator class
        Calculator calc = new Calculator();

        // check to see if the attribute has been applied to a field
        bool fieldTest2 = attrTester.TestForFieldAttribute(typeof(Calculator), "MultiplierField");

        if (fieldTest)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetFieldAttribute(typeof(Calculator), "MultiplierField");
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

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