-
Notifications
You must be signed in to change notification settings - Fork 27
Optimize IDisposable implementations #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,26 @@ namespace Xtensive.Orm | |
{ | ||
public partial class Session | ||
{ | ||
public readonly struct SystemLogicOnlyRegionScope : IDisposable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that we can make it internal and roll back to Do you have any usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is reasonable to restrict access to the scope constructor to keep creations within project There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, this is why I no longer require you to make type internal. I'm talking about the type constructor, there is no reason for it to be used outside project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
{ | ||
private readonly Session session; | ||
private readonly bool prevIsSystemLogicOnly; | ||
|
||
public SystemLogicOnlyRegionScope(Session session) | ||
{ | ||
this.session = session; | ||
prevIsSystemLogicOnly = session.IsSystemLogicOnly; | ||
session.IsSystemLogicOnly = true; | ||
} | ||
|
||
public void Dispose() => session.IsSystemLogicOnly = prevIsSystemLogicOnly; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether only a system logic is enabled. | ||
/// </summary> | ||
internal bool IsSystemLogicOnly { get; set; } | ||
|
||
internal IDisposable OpenSystemLogicOnlyRegion() | ||
{ | ||
var result = new Disposable<Session, bool>(this, IsSystemLogicOnly, | ||
(disposing, session, previousState) => session.IsSystemLogicOnly = previousState); | ||
IsSystemLogicOnly = true; | ||
return result; | ||
} | ||
internal SystemLogicOnlyRegionScope OpenSystemLogicOnlyRegion() => new(this); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.