At the moment, I have some functions which look like this:
private bool inFunction1 = false;
public void function1()
{
if (inFunction1) return;
inFunctio
Without assembly and IL rewriting, there's no way for you to create a custom attribute that modifies the code in the way you describe.
I suggest that you use a delegate-based approach instead, e.g. for functions of a single argument:
static Func WrapAgainstReentry(Func code, Func onReentry)
{
bool entered = false;
return x =>
{
if (entered)
return onReentry(x);
entered = true;
try
{
return code(x);
}
finally
{
entered = false;
}
};
}
This method takes the function to wrap (assuming it matches Func