I wish to create a custom attribute that suppress a Method from being executed in C# even if it is invoked. For example, In the code block below if the method has 'Skip' Attribute it should not be executed even though it is called from Main.
public class MyClass {
public static void main()
{
aMethod();
}
[Skip]
public void aMethod() {
..
}
}
How can I achieve this using reflection in C# ?
In the code snippet below I have managed to extract methods that carry the Skip Attribute, I just can't figure out how to stop them from executing!
MethodInfo[] methodInfos = typeof (MyClass).GetMethods();
foreach (var methodInfo in methodInfos)
{
if (methodInfo.HasAttribute(typeof(SkipAttribute)))
{
// What goes here ??
}
}
Any kinda help or suggestion in the right direction is most welcome :)