After this: Custom Attribute not being hit I'm looking for way to hit method's attributes in my application.
Currently as I know if there's some custom attribute like
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
public MyAttribute()
{
Console.WriteLine("Hello");
}
}
And method that decorated with MyAtrtribute like:
[MyValidation]
public class Service
{
[MyValidation]
public bool GetService(int id)
{
if (id > 100)
{
return true;
}
return false;
}
}
The way to fire this attribute is by calling method service.GetType().GetCustomAttributes(false). The question is: If I want to decorate many methods in many classes what the way to apply the attributes? In my case I want to apply license validation when getting method invokes like createProject(), createUser() etc.
The way like this codes service.GetType().GetCustomAttributes(false)
seems too cumbersome.
I want some central location that will be responsible for firing the attributes applying. There is some elegant solution for it?
Thanks!