Created
January 28, 2017 18:48
-
-
Save AviAvni/00831abbddf4ceca198236de362ed449 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Reflection; | |
| namespace ConsoleApplication21 | |
| { | |
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | |
| class MyAttribute<T> : Attribute | |
| { | |
| public int Value { get; set; } | |
| public MyAttribute() | |
| { | |
| Value = -1; | |
| } | |
| public MyAttribute(int value) | |
| { | |
| Value = value; | |
| } | |
| } | |
| [MyAttribute<int>()] | |
| [MyAttribute<int>(1)] | |
| [MyAttribute<int>(2)] | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var a = typeof(Program).GetCustomAttributes(false); | |
| foreach(var att in a) | |
| { | |
| Console.WriteLine((att as MyAttribute<int>)?.Value.ToString()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment