Advertisement
Guest User

Reflexil 1.4 Preview - Custom Attributes

a guest
Dec 15th, 2011
10,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2.  
  3. namespace AttributeDemo
  4. {
  5.     enum Color
  6.     {
  7.         Red = 1,
  8.         Blue = 2,
  9.         Green = 4,
  10.     }
  11.  
  12.     class FooAttribute : Attribute
  13.     {
  14.         public FooAttribute(Color[] colors, string text, bool check, Type type)
  15.         {
  16.             Console.Write("Colors: ");
  17.             foreach (var color in colors)
  18.                 Console.Write(string.Concat(color, " "));
  19.             Console.WriteLine();
  20.  
  21.             Console.WriteLine(text);
  22.             Console.WriteLine(check);
  23.             Console.WriteLine(type);
  24.         }
  25.     }
  26.  
  27.     class Program
  28.     {
  29.         static void Main(string[] args)
  30.         {
  31.             // force call to CustomAttribute ctor.
  32.             typeof (Program).GetMethod("stub").GetCustomAttributes(true);
  33.            
  34.             Console.ReadKey();
  35.         }
  36.  
  37.         [Foo(new Color[] { Color.Blue }, "hello guys", true, typeof(MarshalByRefObject))]
  38.         public static void stub() { }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement