Skip to content

Commit edf7858

Browse files
committed
Fix up NRT annotations based on netcoreapp3.1 ref assemblies
1 parent a3ca6dc commit edf7858

File tree

9 files changed

+31
-32
lines changed

9 files changed

+31
-32
lines changed

src/Nerdbank.Streams/BufferTextWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BufferTextWriter(IBufferWriter<byte> bufferWriter, Encoding encoding)
9393
}
9494

9595
/// <inheritdoc />
96-
public override Encoding? Encoding => this.encoding;
96+
public override Encoding? Encoding => this.encoding!;
9797

9898
/// <summary>
9999
/// Gets the number of uninitialized characters remaining in <see cref="charBuffer"/>.
@@ -279,7 +279,7 @@ private void EncodeCharacters(bool flushEncoder)
279279

280280
if (MemoryMarshal.TryGetArray(this.memory, out ArraySegment<byte> segment))
281281
{
282-
this.memoryPosition += this.encoder!.GetBytes(this.charBuffer, 0, this.charBufferPosition, segment.Array, segment.Offset + this.memoryPosition, flush: flushEncoder);
282+
this.memoryPosition += this.encoder!.GetBytes(this.charBuffer, 0, this.charBufferPosition, segment.Array!, segment.Offset + this.memoryPosition, flush: flushEncoder);
283283
}
284284
else
285285
{

src/Nerdbank.Streams/MultiplexingStream.Channel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void Dispose()
344344
}
345345
else
346346
{
347-
this.mxStreamIOReaderCompleted!.ContinueWith(finalDisposalAction, this, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).Forget();
347+
this.mxStreamIOReaderCompleted!.ContinueWith(finalDisposalAction!, this, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).Forget();
348348
}
349349
}
350350
}
@@ -801,6 +801,7 @@ private void LocalContentExamined(long bytesExamined)
801801

802802
private async Task AutoCloseOnPipesClosureAsync()
803803
{
804+
Assumes.NotNull(this.mxStreamIOReaderCompleted);
804805
await Task.WhenAll(this.mxStreamIOWriterCompleted.WaitAsync(), this.mxStreamIOReaderCompleted).ConfigureAwait(false);
805806

806807
if (this.TraceSource!.Switch.ShouldTrace(TraceEventType.Information))
@@ -830,13 +831,13 @@ private void DisposeSelfOnFailure(Task task)
830831
{
831832
if (task.IsFaulted)
832833
{
833-
this.Fault(task.Exception.InnerException ?? task.Exception);
834+
this.Fault(task.Exception!.InnerException ?? task.Exception);
834835
}
835836
}
836837
else
837838
{
838839
task.ContinueWith(
839-
(t, s) => ((Channel)s).Fault(t.Exception.InnerException ?? t.Exception),
840+
(t, s) => ((Channel)s!).Fault(t.Exception!.InnerException ?? t.Exception),
840841
this,
841842
CancellationToken.None,
842843
TaskContinuationOptions.OnlyOnFaulted,

src/Nerdbank.Streams/MultiplexingStream.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public Channel CreateChannel(ChannelOptions? options = default)
323323
public Channel AcceptChannel(int id, ChannelOptions? options = default)
324324
{
325325
options = options ?? DefaultChannelOptions;
326-
Channel channel;
326+
Channel? channel;
327327
lock (this.syncObject)
328328
{
329329
Verify.Operation(this.openChannels.TryGetValue(id, out channel), "No channel with that ID found.");
@@ -344,7 +344,7 @@ public Channel AcceptChannel(int id, ChannelOptions? options = default)
344344
/// <exception cref="InvalidOperationException">Thrown if the channel was already accepted.</exception>
345345
public void RejectChannel(int id)
346346
{
347-
Channel channel;
347+
Channel? channel;
348348
lock (this.syncObject)
349349
{
350350
Verify.Operation(this.openChannels.TryGetValue(id, out channel), "No channel with that ID found.");
@@ -409,7 +409,7 @@ public async Task<Channel> OfferChannelAsync(string name, ChannelOptions? option
409409
ChannelId = channel.Id,
410410
};
411411

412-
using (cancellationToken.Register(this.OfferChannelCanceled, channel))
412+
using (cancellationToken.Register(this.OfferChannelCanceled!, channel))
413413
{
414414
await this.SendFrameAsync(header, payload, cancellationToken).ConfigureAwait(false);
415415
await channel.Acceptance.ConfigureAwait(false);
@@ -500,7 +500,7 @@ public async Task<Channel> AcceptChannelAsync(string name, ChannelOptions? optio
500500
}
501501
else
502502
{
503-
using (cancellationToken.Register(this.AcceptChannelCanceled, Tuple.Create(pendingAcceptChannel, name), false))
503+
using (cancellationToken.Register(this.AcceptChannelCanceled!, Tuple.Create(pendingAcceptChannel, name), false))
504504
{
505505
channel = await pendingAcceptChannel!.Task.ConfigureAwait(false);
506506

@@ -783,7 +783,7 @@ private void OnOfferAccepted(FrameHeader header, ReadOnlySequence<byte> payloadB
783783
{
784784
Channel.AcceptanceParameters acceptanceParameters = this.formatter.DeserializeAcceptanceParameters(payloadBuffer);
785785
int channelId = header.RequiredChannelId;
786-
Channel channel;
786+
Channel? channel;
787787
lock (this.syncObject)
788788
{
789789
if (!this.openChannels.TryGetValue(channelId, out channel))
@@ -833,7 +833,7 @@ private void OnOffer(int channelId, ReadOnlySequence<byte> payloadBuffer)
833833

834834
var channel = new Channel(this, offeredLocally: false, channelId, offerParameters);
835835
bool acceptingChannelAlreadyPresent = false;
836-
ChannelOptions options = DefaultChannelOptions;
836+
ChannelOptions? options = DefaultChannelOptions;
837837
lock (this.syncObject)
838838
{
839839
if (this.acceptingChannels.TryGetValue(offerParameters.Name, out var acceptingChannels))
@@ -849,7 +849,7 @@ private void OnOffer(int channelId, ReadOnlySequence<byte> payloadBuffer)
849849
}
850850

851851
acceptingChannelAlreadyPresent = true;
852-
options = (ChannelOptions)candidate.Task.AsyncState;
852+
options = (ChannelOptions?)candidate.Task.AsyncState;
853853
Assumes.NotNull(options);
854854
break;
855855
}
@@ -1078,13 +1078,13 @@ private void DisposeSelfOnFailure(Task task)
10781078
{
10791079
if (task.IsFaulted)
10801080
{
1081-
this.Fault(task.Exception.InnerException ?? task.Exception);
1081+
this.Fault(task.Exception!.InnerException ?? task.Exception);
10821082
}
10831083
}
10841084
else
10851085
{
10861086
task.ContinueWith(
1087-
(t, s) => ((MultiplexingStream)s).Fault(t.Exception.InnerException ?? t.Exception),
1087+
(t, s) => ((MultiplexingStream)s!).Fault(t.Exception!.InnerException ?? t.Exception),
10881088
this,
10891089
CancellationToken.None,
10901090
TaskContinuationOptions.OnlyOnFaulted,

src/Nerdbank.Streams/PipeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static IDuplexPipe UsePipe(this Stream stream, bool allowUnwrap, int size
219219
}
220220
#pragma warning restore CS0618 // Type or member is obsolete
221221

222-
closeStreamAntecedent?.ContinueWith((_, state) => ((Stream)state).Dispose(), stream, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default).Forget();
222+
closeStreamAntecedent?.ContinueWith((_, state) => ((Stream)state!).Dispose(), stream, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default).Forget();
223223
return new DuplexPipe(input, output);
224224
}
225225

@@ -480,7 +480,7 @@ private static PipeReader UsePipeReader(this Stream stream, int sizeHint = 0, Pi
480480
disposeWhenReaderCompleted.ContinueWith(
481481
(_, s1) =>
482482
{
483-
var tuple = (Tuple<Pipe, Stream>)s1;
483+
var tuple = (Tuple<Pipe, Stream>)s1!;
484484
tuple.Item1.Writer.OnReaderCompleted((ex, s2) => ((Stream)s2).Dispose(), tuple.Item2);
485485
},
486486
Tuple.Create(pipe, stream),

src/Nerdbank.Streams/SequenceTextReader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ public override Task<string> ReadToEndAsync()
220220
}
221221

222222
/// <inheritdoc />
223-
public override Task<string> ReadLineAsync()
223+
public override Task<string?> ReadLineAsync()
224224
{
225225
try
226226
{
227-
string result = this.ReadLine();
228-
return Task.FromResult(result);
227+
string? result = this.ReadLine();
228+
return Task.FromResult<string?>(result);
229229
}
230230
catch (Exception ex)
231231
{
232-
return Task.FromException<string>(ex);
232+
return Task.FromException<string?>(ex);
233233
}
234234
}
235235

@@ -304,7 +304,7 @@ private void DecodeChars()
304304

305305
if (MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> segment))
306306
{
307-
this.decoder!.Convert(segment.Array, segment.Offset, segment.Count, this.charBuffer, this.charBufferLength, this.charBuffer.Length - this.charBufferLength, flush: false, out int bytesUsed, out int charsUsed, out bool completed);
307+
this.decoder!.Convert(segment.Array!, segment.Offset, segment.Count, this.charBuffer, this.charBufferLength, this.charBuffer.Length - this.charBufferLength, flush: false, out int bytesUsed, out int charsUsed, out bool completed);
308308
this.charBufferLength += charsUsed;
309309
this.sequencePosition = this.sequence.GetPosition(bytesUsed, this.sequencePosition);
310310
}

src/Nerdbank.Streams/Sequence`1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public Sequence(ArrayPool<T> arrayPool)
124124
/// <param name="sequence">The sequence to convert.</param>
125125
public static implicit operator ReadOnlySequence<T>(Sequence<T> sequence)
126126
{
127-
return sequence.first != null
128-
? new ReadOnlySequence<T>(sequence.first, sequence.first.Start, sequence.last, sequence.last!.End)
127+
return sequence.first is { } first && sequence.last is { } last
128+
? new ReadOnlySequence<T>(first, first.Start, last, last!.End)
129129
: Empty;
130130
}
131131

@@ -139,7 +139,7 @@ public static implicit operator ReadOnlySequence<T>(Sequence<T> sequence)
139139
/// </param>
140140
public void AdvanceTo(SequencePosition position)
141141
{
142-
var firstSegment = (SequenceSegment)position.GetObject();
142+
var firstSegment = (SequenceSegment?)position.GetObject();
143143
if (firstSegment == null)
144144
{
145145
// Emulate PipeReader behavior which is to just return for default(SequencePosition)

src/Nerdbank.Streams/Substream.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public class Substream : Stream, IDisposableObservable, Microsoft.VisualStudio.T
2222

2323
private readonly Stream underlyingStream;
2424

25-
#pragma warning disable SA1011 // Closing square brackets should be spaced correctly
26-
private byte[]? buffer;
27-
#pragma warning restore SA1011 // Closing square brackets should be spaced correctly
25+
private readonly byte[] buffer;
2826

2927
private int count;
3028

@@ -38,7 +36,7 @@ internal Substream(Stream underlyingStream, int minimumBufferSize = DefaultBuffe
3836
}
3937

4038
/// <inheritdoc/>
41-
public bool IsDisposed => this.buffer == null;
39+
public bool IsDisposed { get; private set; }
4240

4341
/// <inheritdoc/>
4442
public override bool CanRead => false;
@@ -85,7 +83,7 @@ public async ValueTask DisposeAsync(CancellationToken cancellationToken = defaul
8583
await this.underlyingStream.FlushAsync(cancellationToken).ConfigureAwait(false);
8684

8785
ArrayPool<byte>.Shared.Return(this.buffer);
88-
this.buffer = null;
86+
this.IsDisposed = true;
8987

9088
this.Dispose();
9189
}
@@ -177,7 +175,7 @@ protected override void Dispose(bool disposing)
177175
this.underlyingStream.Flush();
178176

179177
ArrayPool<byte>.Shared.Return(this.buffer);
180-
this.buffer = null;
178+
this.IsDisposed = true;
181179
}
182180
}
183181

src/Nerdbank.Streams/netcoreapp2.1/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ override Nerdbank.Streams.SequenceTextReader.ReadAsync(System.Memory<char> buffe
194194
override Nerdbank.Streams.SequenceTextReader.ReadAsync(char[]! buffer, int index, int count) -> System.Threading.Tasks.Task<int>!
195195
override Nerdbank.Streams.SequenceTextReader.ReadBlockAsync(System.Memory<char> buffer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<int>
196196
override Nerdbank.Streams.SequenceTextReader.ReadBlockAsync(char[]! buffer, int index, int count) -> System.Threading.Tasks.Task<int>!
197-
override Nerdbank.Streams.SequenceTextReader.ReadLineAsync() -> System.Threading.Tasks.Task<string!>!
197+
override Nerdbank.Streams.SequenceTextReader.ReadLineAsync() -> System.Threading.Tasks.Task<string?>!
198198
override Nerdbank.Streams.SequenceTextReader.ReadToEndAsync() -> System.Threading.Tasks.Task<string!>!
199199
override Nerdbank.Streams.SimplexStream.CanRead.get -> bool
200200
override Nerdbank.Streams.SimplexStream.CanSeek.get -> bool

src/Nerdbank.Streams/netstandard2.0/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ override Nerdbank.Streams.SequenceTextReader.Read() -> int
185185
override Nerdbank.Streams.SequenceTextReader.Read(char[]! buffer, int index, int count) -> int
186186
override Nerdbank.Streams.SequenceTextReader.ReadAsync(char[]! buffer, int index, int count) -> System.Threading.Tasks.Task<int>!
187187
override Nerdbank.Streams.SequenceTextReader.ReadBlockAsync(char[]! buffer, int index, int count) -> System.Threading.Tasks.Task<int>!
188-
override Nerdbank.Streams.SequenceTextReader.ReadLineAsync() -> System.Threading.Tasks.Task<string!>!
188+
override Nerdbank.Streams.SequenceTextReader.ReadLineAsync() -> System.Threading.Tasks.Task<string?>!
189189
override Nerdbank.Streams.SequenceTextReader.ReadToEndAsync() -> System.Threading.Tasks.Task<string!>!
190190
override Nerdbank.Streams.SimplexStream.CanRead.get -> bool
191191
override Nerdbank.Streams.SimplexStream.CanSeek.get -> bool

0 commit comments

Comments
 (0)