Skip to content

Commit a9b9455

Browse files
committed
Convert Connection to auto-implemented property.
1 parent aa7a826 commit a9b9455

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlTransaction.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ public override void Commit() =>
1313
CommitAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
1414

1515
public Task CommitAsync(CancellationToken cancellationToken = default) =>
16-
CommitAsync(m_connection?.AsyncIOBehavior ?? IOBehavior.Asynchronous, cancellationToken);
16+
CommitAsync(Connection?.AsyncIOBehavior ?? IOBehavior.Asynchronous, cancellationToken);
1717

1818
internal async Task CommitAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
1919
{
2020
VerifyNotDisposed();
21-
if (m_connection == null)
21+
if (Connection == null)
2222
throw new InvalidOperationException("Already committed or rolled back.");
2323

24-
if (m_connection.CurrentTransaction == this)
24+
if (Connection.CurrentTransaction == this)
2525
{
26-
using (var cmd = new MySqlCommand("commit", m_connection, this))
26+
using (var cmd = new MySqlCommand("commit", Connection, this))
2727
await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
28-
m_connection.CurrentTransaction = null;
29-
m_connection = null;
28+
Connection.CurrentTransaction = null;
29+
Connection = null;
3030
}
31-
else if (m_connection.CurrentTransaction != null)
31+
else if (Connection.CurrentTransaction != null)
3232
{
3333
throw new InvalidOperationException("This is not the active transaction.");
3434
}
35-
else if (m_connection.CurrentTransaction == null)
35+
else if (Connection.CurrentTransaction == null)
3636
{
3737
throw new InvalidOperationException("There is no active transaction.");
3838
}
@@ -42,33 +42,33 @@ public override void Rollback() =>
4242
RollbackAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
4343

4444
public Task RollbackAsync(CancellationToken cancellationToken = default) =>
45-
RollbackAsync(m_connection?.AsyncIOBehavior ?? IOBehavior.Asynchronous, cancellationToken);
45+
RollbackAsync(Connection?.AsyncIOBehavior ?? IOBehavior.Asynchronous, cancellationToken);
4646

4747
internal async Task RollbackAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
4848
{
4949
VerifyNotDisposed();
50-
if (m_connection == null)
50+
if (Connection == null)
5151
throw new InvalidOperationException("Already committed or rolled back.");
5252

53-
if (m_connection.CurrentTransaction == this)
53+
if (Connection.CurrentTransaction == this)
5454
{
55-
using (var cmd = new MySqlCommand("rollback", m_connection, this))
55+
using (var cmd = new MySqlCommand("rollback", Connection, this))
5656
await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
57-
m_connection.CurrentTransaction = null;
58-
m_connection = null;
57+
Connection.CurrentTransaction = null;
58+
Connection = null;
5959
}
60-
else if (m_connection.CurrentTransaction != null)
60+
else if (Connection.CurrentTransaction != null)
6161
{
6262
throw new InvalidOperationException("This is not the active transaction.");
6363
}
64-
else if (m_connection.CurrentTransaction == null)
64+
else if (Connection.CurrentTransaction == null)
6565
{
6666
throw new InvalidOperationException("There is no active transaction.");
6767
}
6868
}
6969

70-
public new MySqlConnection Connection => m_connection;
71-
protected override DbConnection DbConnection => m_connection;
70+
public new MySqlConnection Connection { get; private set; }
71+
protected override DbConnection DbConnection => Connection;
7272
public override IsolationLevel IsolationLevel { get; }
7373

7474
protected override void Dispose(bool disposing)
@@ -78,16 +78,16 @@ protected override void Dispose(bool disposing)
7878
if (disposing)
7979
{
8080
m_isDisposed = true;
81-
if (m_connection?.CurrentTransaction == this)
81+
if (Connection?.CurrentTransaction == this)
8282
{
83-
if (m_connection.Session.IsConnected)
83+
if (Connection.Session.IsConnected)
8484
{
85-
using (var cmd = new MySqlCommand("rollback", m_connection, this))
85+
using (var cmd = new MySqlCommand("rollback", Connection, this))
8686
cmd.ExecuteNonQuery();
8787
}
88-
m_connection.CurrentTransaction = null;
88+
Connection.CurrentTransaction = null;
8989
}
90-
m_connection = null;
90+
Connection = null;
9191
}
9292
}
9393
finally
@@ -98,7 +98,7 @@ protected override void Dispose(bool disposing)
9898

9999
internal MySqlTransaction(MySqlConnection connection, IsolationLevel isolationLevel)
100100
{
101-
m_connection = connection;
101+
Connection = connection;
102102
IsolationLevel = isolationLevel;
103103
}
104104

@@ -108,7 +108,6 @@ private void VerifyNotDisposed()
108108
throw new ObjectDisposedException(nameof(MySqlTransaction));
109109
}
110110

111-
MySqlConnection m_connection;
112111
bool m_isDisposed;
113112
}
114113
}

0 commit comments

Comments
 (0)