I found a way but I am not sure it is the easiest way or the most cost-effective way. Here is the solution I found...
Code:
using System;
using System.Reflection;
namespace Test
{
public class MyCustomAttribute : Attribute
{
public string item;
public MyCustomAttribute()
{
this.item = item;
}
}
[MyCustom(item="myitemvalue")]
class MyClassWithTheAttributeApplied
{
public static void SomeMethod()
{
MemberInfo info = typeof(MyClassWithTheAttributeApplied);
object[] o = info.GetCustomAttributes(true);
foreach(object t in o)
Console.WriteLine(((MyCustomAttribute)t).item);
}
}
class MainClass
{
[STAThread]
static void Main(string[] args)
{
MyClassWithTheAttributeApplied.SomeMethod();
}
}
}
The above code will output
myitemvalue. Please comment on the post if you know a better way to do this. Thanks.
Jacob.