Example #1
0
        // Ex 2: Get defined attribute using Attribute class
        public void Ex2_Attribute()
        {
            ExAttribute ea = new ExAttribute();

            MemberInfo[] m1 = ea.GetType().GetMember("conditionalMethod");

            if (m1.Length > 0 && Attribute.IsDefined(m1[0], typeof(ConditionalAttribute)))
            {
                Console.WriteLine("ConditionalAttribute exists on {0}", m1[0].ToString());
            }
        }
Example #2
0
        public virtual void Ex3_CustomAttribute([ExCustom("Param")] string s)
        {
            ExAttribute ea = new ExAttribute();

            MethodInfo m1 = ea.GetType().GetMethod("Ex3_CustomAttribute", new Type[] { typeof(string) });

            if (m1 != null && Attribute.IsDefined(m1, typeof(ExCustomAttribute)))
            {
                ExCustomAttribute a = (ExCustomAttribute)m1.GetCustomAttribute(typeof(ExCustomAttribute));

                Console.WriteLine("ExCustomAttribute defined on Ex3_CustomAttribute: {0}", a.Prop1);
            }
        }