I got a disposable class with following constructor:
public MyClass(bool allowed){
if(allowed) return;
else { // leave outer using }
}
And it is used like this
using (new MyClass(false))
{
DoSomething();
}
Or like following
using (new MyClass(true))
{
DoSomething();
}
How to achieve that only the one called with (true) will execute the block (aka DoSomething()) and if it is called with (false) it will not execute the block?