Let's say we have two classes:
MainClass
:
public class MainClass
{
[CustomAttribute("John Smith", 55)]
ItemClass ic = new ItemClass();
}
ItemClass
:
public class ItemClass
{
public void TestMethod()
{
// I want to get the "John Smith" and 55 from here
}
}
And also a custom attribute CustomAttribute
:
public class CustomAttribute : Attribute
{
public string Name;
public int Age;
public CustomAttribute(string name, string age)
{
this.Name = name;
this.Age = age;
}
}
Is there any way I can get the that attribute (defined in MainClass) from inside an instance of my ItemClass?
In other words, how can I get "John Smith"
and 55
from inside TestMethod()
?