Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace AttributeDemo
- {
- enum Color
- {
- Red = 1,
- Blue = 2,
- Green = 4,
- }
- class FooAttribute : Attribute
- {
- public FooAttribute(Color[] colors, string text, bool check, Type type)
- {
- Console.Write("Colors: ");
- foreach (var color in colors)
- Console.Write(string.Concat(color, " "));
- Console.WriteLine();
- Console.WriteLine(text);
- Console.WriteLine(check);
- Console.WriteLine(type);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // force call to CustomAttribute ctor.
- typeof (Program).GetMethod("stub").GetCustomAttributes(true);
- Console.ReadKey();
- }
- [Foo(new Color[] { Color.Blue }, "hello guys", true, typeof(MarshalByRefObject))]
- public static void stub() { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement