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()); }
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(); } }
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); }
public static void Main() { FooAttribute foo = (FooAttribute)(typeof(Tests).GetCustomAttributes(false) [0]); Console.WriteLine(foo.Separator); }
public void GetCustomAttribute() { FooAttribute foo = typeof(Bar).GetCustomAttribute <FooAttribute> (); Assert.IsNotNull(foo); // cannot assert the value }