Skip to content

Instantly share code, notes, and snippets.

@binki
Last active January 2, 2017 17:18
Show Gist options
  • Save binki/afdf5314f593ebd95800865a26349283 to your computer and use it in GitHub Desktop.
Save binki/afdf5314f593ebd95800865a26349283 to your computer and use it in GitHub Desktop.
csharp attributes allow arrays
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