I am studying about attributes. I am new in them. I have a query. I have made some Custom Attribute class of my own. let me show some code.
public class MySpecialAttribute : Attribute
{
public string Name { get; set; }
public int Age { get; set; }
}
I have used this attribute on some methods.
public class UseOfAttribute
{
[MySpecial]
public void Hello()
{
Console.WriteLine("Hello");
}
[MySpecial]
public void Bye()
{
Console.WriteLine("Bye");
}
public void TC()
{
Console.WriteLine("TC");
}
}
Now my question is that I fetch all the methods with MySpecialAttribute at runtime and Can I change Name and age property at runtime. If I can do this then what is the way?
class Program
{
static void Main(string[] args)
{
var allMethods = typeof(UseOfAttribute).GetRuntimeMethods().Where(r => r.IsDefined(typeof(MySpecialAttribute))).ToList();
}
}
This is the way of fetching my methods. Can anyone tell me? Thanks in advance.