コード例 #1
0
        static void Main(string[] args)
        {
            Type classType = typeof(DecoratedClass);

            object[] customAttributes = classType.GetCustomAttributes(true);
            foreach (object customAttribute in customAttributes)
            {
                WriteLine($"Attribute of type {customAttribute} found");
                DoesInterestingThingsAttribute interestingAttribute = customAttribute as DoesInterestingThingsAttribute;
                if (interestingAttribute != null)
                {
                    WriteLine($"This class does {interestingAttribute.WhatDoesItDo} x {interestingAttribute.HowManyTimes}!");
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SHAREVIEW/CSharpRMJD-6-
        static void Main(string[] args)
        {
            Type classType = typeof(DecoratedClass);

            object[] customAttributes = classType.GetCustomAttributes(true);
            foreach (object customAttribute in customAttributes)
            {
                Console.WriteLine("Attribute of type {0} found.", customAttribute);
                DoesInterestingThingsAttribute interestingAttribute =
                    customAttribute as DoesInterestingThingsAttribute;
                if (interestingAttribute != null)
                {
                    Console.WriteLine("This class does {0} x {1}!",
                                      interestingAttribute.WhatDoesItDo,
                                      interestingAttribute.HowManyTimes);
                }
            }

            Console.ReadKey();
        }