Last active
January 2, 2017 17:18
-
-
Save binki/afdf5314f593ebd95800865a26349283 to your computer and use it in GitHub Desktop.
csharp attributes allow arrays
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
A | |
B | |
C |
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; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var value in typeof(MyClass).GetCustomAttribute<MyAttribute>().Values) | |
{ | |
Console.WriteLine(value); | |
} | |
} | |
} | |
[My("A", "B", "C")] | |
class MyClass | |
{ | |
} | |
class MyAttribute : Attribute | |
{ | |
public string[] Values { get; } | |
public MyAttribute(params string[] values) | |
{ | |
Values = values; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment