Skip to content

Instantly share code, notes, and snippets.

@AviAvni
Created January 28, 2017 18:48
Show Gist options
  • Select an option

  • Save AviAvni/00831abbddf4ceca198236de362ed449 to your computer and use it in GitHub Desktop.

Select an option

Save AviAvni/00831abbddf4ceca198236de362ed449 to your computer and use it in GitHub Desktop.
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