@@ -16,10 +16,24 @@ namespace Xtensive.Orm.Operations
1616 /// </summary>
1717 public sealed class OperationRegistry
1818 {
19+ public readonly struct SystemOperationRegistrationScope : IDisposable
20+ {
21+ private readonly OperationRegistry registry ;
22+ private readonly bool prevIsSystemOperationRegistrationEnabled ;
23+
24+ public SystemOperationRegistrationScope ( OperationRegistry registry , bool enable )
25+ {
26+ this . registry = registry ;
27+ prevIsSystemOperationRegistrationEnabled = registry . IsSystemOperationRegistrationEnabled ;
28+ registry . IsSystemOperationRegistrationEnabled = enable ;
29+ }
30+
31+ public void Dispose ( ) => registry . IsSystemOperationRegistrationEnabled = prevIsSystemOperationRegistrationEnabled ;
32+ }
33+
1934 private readonly ICompletableScope blockingScope ;
2035 private bool isOperationRegistrationEnabled = true ;
2136 private bool isUndoOperationRegistrationEnabled = true ;
22- private bool isSystemOperationRegistrationEnabled = true ;
2337 private Collections . Deque < ICompletableScope > scopes = new Collections . Deque < ICompletableScope > ( ) ;
2438
2539 /// <summary>
@@ -41,10 +55,7 @@ public bool IsRegistrationEnabled {
4155 /// <summary>
4256 /// Gets a value indicating whether system operation registration is enabled.
4357 /// </summary>
44- public bool IsSystemOperationRegistrationEnabled {
45- get { return isSystemOperationRegistrationEnabled ; }
46- internal set { isSystemOperationRegistrationEnabled = value ; }
47- }
58+ public bool IsSystemOperationRegistrationEnabled { get ; internal set ; } = true ;
4859
4960 /// <summary>
5061 /// Gets a value indicating whether this instance can register operation
@@ -219,29 +230,13 @@ public IDisposable DisableUndoOperationRegistration()
219230 /// Temporarily disables system operation logging.
220231 /// </summary>
221232 /// <returns>An <see cref="IDisposable"/> object enabling the logging back on its disposal.</returns>
222- public IDisposable DisableSystemOperationRegistration ( )
223- {
224- if ( ! isSystemOperationRegistrationEnabled )
225- return null ;
226- var result = new Disposable < OperationRegistry , bool > ( this , isSystemOperationRegistrationEnabled ,
227- ( disposing , _this , previousState ) => _this . isSystemOperationRegistrationEnabled = previousState ) ;
228- isSystemOperationRegistrationEnabled = false ;
229- return result ;
230- }
233+ public SystemOperationRegistrationScope DisableSystemOperationRegistration ( ) => new ( this , false ) ;
231234
232235 /// <summary>
233236 /// Temporarily enables system operation logging.
234237 /// </summary>
235238 /// <returns>An <see cref="IDisposable"/> object disabling the logging back on its disposal.</returns>
236- public IDisposable EnableSystemOperationRegistration ( )
237- {
238- if ( isSystemOperationRegistrationEnabled )
239- return null ;
240- var result = new Disposable < OperationRegistry , bool > ( this , isSystemOperationRegistrationEnabled ,
241- ( disposing , _this , previousState ) => _this . isSystemOperationRegistrationEnabled = previousState ) ;
242- isSystemOperationRegistrationEnabled = true ;
243- return result ;
244- }
239+ public SystemOperationRegistrationScope EnableSystemOperationRegistration ( ) => new ( this , true ) ;
245240
246241 /// <summary>
247242 /// Registers the operation.
0 commit comments