Пример #1
0
        public void CaptureAttributes()
        {
            var attribute = new FooAttribute();

            ((IAttributeCollection)attribute).Add(new Attribute1());
            ((IAttributeCollection)attribute).AddRange(new Attribute[] { new Attribute2(), new Attribute3() });

            Assert.True(((IAttributeCollection)attribute).OfType <Attribute1>().Any());
            Assert.True(((IAttributeCollection)attribute).OfType <Attribute2>().Any());
            Assert.True(((IAttributeCollection)attribute).OfType <Attribute3>().Any());
        }
Пример #2
0
    public static void Main()
    {
        FooAttribute foo = (FooAttribute)typeof(Test)
                           .GetCustomAttributes(false) [0];

        if (foo.StringValues [0] != "foo" ||
            foo.StringValues [1] != "bar" ||
            foo.StringValues [2] != "baz" ||
            1 != (int)foo.ObjectValues [0] ||
            'A' != (char)foo.ObjectValues [1] ||
            "B" != (string)foo.ObjectValues [2] ||
            foo.Types [0] != typeof(int) ||
            foo.Types [1] != typeof(Type)
            )
        {
            throw new ApplicationException();
        }
    }
Пример #3
0
    public static int Main()
    {
        FooAttribute foo = (FooAttribute)typeof(Test)
                           .GetCustomAttributes(false) [0];

        if (foo.StringValues [0] != "foo" ||
            foo.StringValues [1] != "bar" ||
            foo.StringValues [2] != "baz" ||
            1 != (int)foo.ObjectValues [0] ||
            'A' != (char)foo.ObjectValues [1] ||
            "B" != (string)foo.ObjectValues [2] ||
            EnumType.X != foo.EnumValues [0] ||
            EnumType.Y != foo.EnumValues [1] ||
            foo.Types [0] != typeof(int) ||
            foo.Types [1] != typeof(Type)
            )
        {
            return(1);
        }

        return(0);
    }
Пример #4
0
    public static void Main()
    {
        FooAttribute foo = (FooAttribute)(typeof(Tests).GetCustomAttributes(false) [0]);

        Console.WriteLine(foo.Separator);
    }
Пример #5
0
        public void GetCustomAttribute()
        {
            FooAttribute foo = typeof(Bar).GetCustomAttribute <FooAttribute> ();

            Assert.IsNotNull(foo);              // cannot assert the value
        }