Skip to content

Commit b5e3443

Browse files
committed
Use assumer method instead of null-ignoring operator.
1 parent 1e87a62 commit b5e3443

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

PSql/Commands/ConnectedCmdlet.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright Subatomix Research Inc.
22
// SPDX-License-Identifier: MIT
33

4+
using System.Diagnostics;
5+
46
namespace PSql.Commands;
57

68
/// <summary>
@@ -71,4 +73,15 @@ public virtual void Dispose()
7173
Connection = null;
7274
_ownsConnection = false;
7375
}
76+
77+
#if !DEBUG
78+
[ExcludeFromCodeCoverage]
79+
#endif
80+
[Conditional("DEBUG")]
81+
[MemberNotNull(nameof(Connection))]
82+
protected void AssumeBeginProcessingInvoked()
83+
{
84+
if (Connection is null)
85+
throw new InvalidOperationException("BeginProcessing() has not been invoked.");
86+
}
7487
}

PSql/Commands/InvokeSqlCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ private IEnumerator<object> ExecuteAndProjectToObjects(string batch)
118118
{
119119
const int DefaultTimeoutSeconds = 30;
120120

121+
AssumeBeginProcessingInvoked();
122+
121123
var timeout = Timeout.HasValue
122124
? (int) Timeout.Value.TotalSeconds
123125
: DefaultTimeoutSeconds;
124126

125-
// NULLS: _command created in BeginProcessing
126-
return Connection!.InnerConnection.ExecuteAndProjectTo(
127+
return Connection.InnerConnection.ExecuteAndProjectTo(
127128
batch, new PSObjectBuilder(), timeout, UseSqlTypes
128129
);
129130
}

0 commit comments

Comments
 (0)