Skip to content

Commit b2c3bbf

Browse files
committed
Fix code formatting in the Transaction class
1 parent ac8112c commit b2c3bbf

1 file changed

Lines changed: 41 additions & 28 deletions

File tree

Orm/Xtensive.Orm/Orm/Transaction.cs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public sealed partial class Transaction : IHasExtensions
3030
public static Transaction Current {
3131
get {
3232
var session = Session.Current;
33-
return session != null ? session.Transaction : null;
33+
return session?.Transaction;
3434
}
3535
}
3636

@@ -40,12 +40,17 @@ public static Transaction Current {
4040
/// if active <see cref="Transaction"/> is not found.
4141
/// </summary>
4242
/// <returns>Current transaction.</returns>
43-
/// <exception cref="InvalidOperationException"><see cref="Transaction.Current"/> <see cref="Transaction"/> is <see langword="null" />.</exception>
43+
/// <exception cref="InvalidOperationException">
44+
/// <see cref="Transaction.Current"/> <see cref="Transaction"/> is <see langword="null" />.
45+
/// </exception>
4446
public static Transaction Demand()
4547
{
4648
var current = Current;
47-
if (current==null)
48-
throw new InvalidOperationException(Strings.ExActiveTransactionIsRequiredForThisOperationUseSessionOpenTransactionToOpenIt);
49+
if (current == null) {
50+
throw new InvalidOperationException(
51+
Strings.ExActiveTransactionIsRequiredForThisOperationUseSessionOpenTransactionToOpenIt);
52+
}
53+
4954
return current;
5055
}
5156

@@ -56,7 +61,7 @@ public static Transaction Demand()
5661
/// <exception cref="InvalidOperationException"><see cref="Transaction.Current"/> <see cref="Transaction"/> is <see langword="null" />.</exception>
5762
public static void Require(Session session)
5863
{
59-
ArgumentValidator.EnsureArgumentNotNull(session, "session");
64+
ArgumentValidator.EnsureArgumentNotNull(session, nameof(session));
6065
session.DemandTransaction();
6166
}
6267

@@ -114,11 +119,11 @@ public static void Require(Session session)
114119
/// Gets the start time of this transaction.
115120
/// </summary>
116121
public DateTime TimeStamp { get; private set; }
117-
122+
118123
/// <summary>
119124
/// Gets a value indicating whether this transaction is a nested transaction.
120125
/// </summary>
121-
public bool IsNested { get { return Outer!=null; } }
126+
public bool IsNested => Outer != null;
122127

123128
/// <summary>
124129
/// Gets <see cref="StateLifetimeToken"/> associated with this transaction.
@@ -128,13 +133,7 @@ public static void Require(Session session)
128133
#region IHasExtensions Members
129134

130135
/// <inheritdoc/>
131-
public IExtensionCollection Extensions {
132-
get {
133-
if (extensions==null)
134-
extensions = new ExtensionCollection();
135-
return extensions;
136-
}
137-
}
136+
public IExtensionCollection Extensions => extensions ??= new ExtensionCollection();
138137

139138
#endregion
140139

@@ -155,22 +154,28 @@ public IExtensionCollection Extensions {
155154
public bool AreChangesVisibleTo(Transaction otherTransaction)
156155
{
157156
ArgumentValidator.EnsureArgumentNotNull(otherTransaction, "otherTransaction");
158-
if (Outermost!=otherTransaction.Outermost)
157+
if (Outermost != otherTransaction.Outermost) {
159158
return false;
159+
}
160+
160161
var t = this;
161162
var outermost = t.Outermost;
162-
while (t!=outermost && t!=otherTransaction && t.State==TransactionState.Committed)
163+
while (t != outermost && t != otherTransaction && t.State == TransactionState.Committed) {
163164
t = t.Outer;
165+
}
166+
164167
return t.State.IsActive();
165168
}
166-
169+
167170
#region Private / internal methods
168-
171+
169172
internal void Begin()
170173
{
171174
Session.BeginTransaction(this);
172-
if (Outer!=null)
175+
if (Outer != null) {
173176
Outer.inner = this;
177+
}
178+
174179
State = TransactionState.Active;
175180
}
176181

@@ -179,7 +184,7 @@ internal async ValueTask Commit(bool isAsync)
179184
EnsureIsActive();
180185
State = TransactionState.Committing;
181186
try {
182-
if (inner!=null) {
187+
if (inner != null) {
183188
throw new InvalidOperationException(Strings.ExCanNotCompleteOuterTransactionInnerTransactionIsActive);
184189
}
185190

@@ -189,7 +194,8 @@ internal async ValueTask Commit(bool isAsync)
189194
await Rollback(isAsync).ConfigureAwait(false);
190195
throw;
191196
}
192-
if (Outer!=null) {
197+
198+
if (Outer != null) {
193199
PromoteLifetimeTokens();
194200
}
195201
else if (Session.Configuration.Supports(SessionOptions.NonTransactionalReads)) {
@@ -209,7 +215,7 @@ internal async ValueTask Rollback(bool isAsync)
209215
State = TransactionState.RollingBack;
210216
try {
211217
try {
212-
if (inner!=null) {
218+
if (inner != null) {
213219
await inner.Rollback(isAsync).ConfigureAwait(false);
214220
}
215221
}
@@ -226,21 +232,26 @@ internal async ValueTask Rollback(bool isAsync)
226232

227233
private void EndTransaction()
228234
{
229-
if (Outer!=null)
235+
if (Outer != null) {
230236
Outer.inner = null;
237+
}
238+
231239
Session.CompleteTransaction(this);
232240
}
233241

234242
private void EnsureIsActive()
235243
{
236-
if (!State.IsActive())
244+
if (!State.IsActive()) {
237245
throw new InvalidOperationException(Strings.ExTransactionIsNotActive);
246+
}
238247
}
239248

240249
private void ExpireLifetimeTokens()
241250
{
242-
foreach (var token in lifetimeTokens)
251+
foreach (var token in lifetimeTokens) {
243252
token.Expire();
253+
}
254+
244255
ClearLifetimeTokens();
245256
}
246257

@@ -266,7 +277,8 @@ internal Transaction(Session session, IsolationLevel isolationLevel, bool isAuto
266277
{
267278
}
268279

269-
internal Transaction(Session session, IsolationLevel isolationLevel, bool isAutomatic, Transaction outer, string savepointName)
280+
internal Transaction(Session session, IsolationLevel isolationLevel, bool isAutomatic, Transaction outer,
281+
string savepointName)
270282
{
271283
lifetimeTokens = new List<StateLifetimeToken>();
272284

@@ -280,14 +292,15 @@ internal Transaction(Session session, IsolationLevel isolationLevel, bool isAuto
280292
LifetimeToken = new StateLifetimeToken();
281293
lifetimeTokens.Add(LifetimeToken);
282294

283-
if (outer!=null) {
295+
if (outer != null) {
284296
Outer = outer;
285297
Guid = outer.Guid;
286298
Outermost = outer.Outermost;
287299
SavepointName = savepointName;
288300
}
289-
else
301+
else {
290302
Outermost = this;
303+
}
291304
}
292305
}
293306
}

0 commit comments

Comments
 (0)