With respect to question 2, it is possible to work around it by providing a different interface to code consumers. Instead of providing an open class that implements IDisposable
, and hoping they wrap it in using
, you can provide a static method that executes a function to execute in a “suppressed” context:
public static class EventSuppressor { public void Suppress(Action action) { using (var s = new SuppressActions()) { action(); } } private class SuppressActions : IDisposable { ... } }
Consumers can then use this as follows:
EventSuppressor.Suppress(() => {
Of course, you need to decide if this project is suitable, as this will lead to additional function calls, compiler-generated classes and closure, etc.
source share