How can I identify down the call chain the encompassing using block? I mean without saving in a static or global the object created by using block nor passing it around. If I have:
using(new Foo()) { A(); } void A() { B(); } inside function B I want to be able to identify and access Foo instance. It would be even nicer to get also the upper encompassing using block if any and so on.
FoointoAand then intoB.Fooinstance via parameters is the cleanest and most maintainable solution. If you end up forwarding it through a chain of methods and only the deepest call actually uses it then you might want to rethink your design. Unfortunately there is no magic bullet to solve this problem.