Пример #1
0
        public void Test_Method1Attribute()
        {
            MethodInfo       m = typeof(AttributeClass1).GetMethod("Add");
            Method1Attribute a = m.GetMyAttribute <Method1Attribute>();

            Assert.AreEqual("d16da143-0d90-4e27-a665-83a2639966ea", a.Flag);
        }
Пример #2
0
        public void Test_Register_Array()
        {
            string           flag2 = "22222222222222222222";
            string           flag3 = "3333333333333333333333";
            Method1Attribute a2    = new Method1Attribute {
                Flag = flag2
            };
            Method1Attribute a3 = new Method1Attribute {
                Flag = flag3
            };

            // 模拟 ActionExecutor 标记了 Type1Attribute
            MethodInfo method = typeof(HttpResponse).GetMethod("Redirect", new Type[] { typeof(string) });

            AttributeCache.Register(method, new Method1Attribute[] { a2, a3 });

            // 获取 Type1Attribute
            Method1Attribute[] aa = method.GetMyAttributes <Method1Attribute>();
            Assert.AreEqual(2, aa.Length);
            Assert.AreEqual(flag2, aa[0].Flag);
            Assert.AreEqual(flag3, aa[1].Flag);
        }