I want to be able to add some code to the beginning of a method if it has a certain attribute. For example, I want it to return immediately if it has a particular attribute and it is Wednesday:
[Return()]
public void MyMethod()
{
//If [Return()] attribute and its Wednesday, it returns and never "Does Stuff"
//Do Stuff
}
I have the start to my Attribute, but I cannot figure out how to run the code ahead of the method.
[AttributeUsage(AttributeTargets.Method)]
public class ReturnAttribute : Attribute
{
public void Return()
{
if(Today == Wednesday)
{
return;
}
{
}
I know the ReturnAttribute
is incorrect. I posted that code to show how close (or far) I have come.
How can I insert code at the beginning of a method, if that method is marked with the specified attribute?