Skip to content

Commit 667d4fe

Browse files
Merge pull request #30 from Open-NET-Libraries/v6
V6
2 parents e17860f + cf68b25 commit 667d4fe

15 files changed

+128
-44
lines changed

.editorconfig

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ csharp_style_var_when_type_is_apparent = true:suggestion
8080

8181
# Expression-bodied members
8282
csharp_style_expression_bodied_accessors = true:suggestion
83-
csharp_style_expression_bodied_constructors = when_on_single_line
83+
csharp_style_expression_bodied_constructors = when_on_single_line:silent
8484
csharp_style_expression_bodied_indexers = true:suggestion
8585
csharp_style_expression_bodied_lambdas = true:suggestion
8686
csharp_style_expression_bodied_local_functions = true:suggestion
@@ -103,8 +103,8 @@ csharp_prefer_static_local_function = true
103103
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
104104

105105
# Code-block preferences
106-
csharp_prefer_braces = when_multiline
107-
csharp_prefer_simple_using_statement = true
106+
csharp_prefer_braces = when_multiline:silent
107+
csharp_prefer_simple_using_statement = true:suggestion
108108
csharp_style_namespace_declarations = file_scoped:suggestion
109109

110110
# Expression-level preferences
@@ -222,3 +222,24 @@ dotnet_diagnostic.RCS1123.severity = silent
222222

223223
# IDE0290: Don't suggest primary constructor.
224224
dotnet_diagnostic.IDE0290.severity = silent
225+
csharp_style_prefer_method_group_conversion = true:silent
226+
csharp_style_prefer_top_level_statements = true:silent
227+
csharp_style_prefer_primary_constructors = true:suggestion
228+
229+
[*.{cs,vb}]
230+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
231+
tab_width = 4
232+
indent_size = 4
233+
end_of_line = crlf
234+
dotnet_style_coalesce_expression = true:warning
235+
dotnet_style_null_propagation = true:warning
236+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
237+
dotnet_style_prefer_auto_properties = true:suggestion
238+
dotnet_style_object_initializer = true:suggestion
239+
dotnet_style_prefer_collection_expression = true:suggestion
240+
dotnet_style_collection_initializer = true:suggestion
241+
dotnet_style_prefer_simplified_boolean_expressions = true:warning
242+
dotnet_style_prefer_conditional_expression_over_assignment = true:warning
243+
dotnet_style_prefer_conditional_expression_over_return = true:warning
244+
dotnet_style_explicit_tuple_names = true:suggestion
245+
dotnet_diagnostic.CA1510.severity = none

Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Open.ChannelExtensions.Tests/BasicTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ public static async Task BatchJoin(int testSize, int batchSize)
405405
Assert.True(result.SequenceEqual(range));
406406
}
407407

408-
#if NET5_0_OR_GREATER
409408
[Theory]
410409
[InlineData(11)]
411410
[InlineData(51)]
@@ -439,7 +438,6 @@ async IAsyncEnumerable<int> Samples()
439438
}
440439
}
441440
}
442-
#endif
443441

444442
[Theory]
445443
[InlineData(testSize1)]

Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
@@ -12,13 +12,13 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
16-
<PackageReference Include="xunit" Version="2.4.1" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16+
<PackageReference Include="xunit" Version="2.6.6" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>
21-
<PackageReference Include="coverlet.collector" Version="3.0.3">
21+
<PackageReference Include="coverlet.collector" Version="6.0.0">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>

Open.ChannelExtensions/BatchingChannelReader.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected BatchingChannelReader(
3333
/// </summary>
3434
public bool ForceBatch() => TryPipeItems(true);
3535

36-
void ForceBatch(object obj) => ForceBatch();
36+
void ForceBatch(object? obj) => ForceBatch();
3737

3838
long _timeout = -1;
3939
Timer? _timer;
@@ -224,15 +224,15 @@ protected override async ValueTask<bool> WaitToReadAsyncCore(
224224

225225
if (b.IsCompleted)
226226
{
227-
tokenSource.Cancel();
227+
await tokenSource.CancelAsync().ConfigureAwait(false);
228228
return await b.ConfigureAwait(false);
229229
}
230230

231231
// WhenAny will not throw when a task is cancelled.
232232
await Task.WhenAny(s.AsTask(), b).ConfigureAwait(false);
233233
if (b.IsCompleted) // Assuming it was bufferWait that completed.
234234
{
235-
tokenSource.Cancel();
235+
await tokenSource.CancelAsync().ConfigureAwait(false);
236236
return await b.ConfigureAwait(false);
237237
}
238238

@@ -254,19 +254,31 @@ public QueueBatchingChannelReader(ChannelReader<T> source, int batchSize, bool s
254254

255255
/// <inheritdoc />
256256
[MethodImpl(MethodImplOptions.AggressiveInlining)]
257-
protected override void AddBatchItem(Queue<T> batch, T item) => batch.Enqueue(item);
257+
protected override void AddBatchItem(Queue<T> batch, T item)
258+
{
259+
Debug.Assert(batch is not null);
260+
batch!.Enqueue(item);
261+
}
258262

259263
/// <inheritdoc />
260264
[MethodImpl(MethodImplOptions.AggressiveInlining)]
261265
protected override Queue<T> CreateBatch(int capacity) => new(capacity);
262266

263267
/// <inheritdoc />
264268
[MethodImpl(MethodImplOptions.AggressiveInlining)]
265-
protected override int GetBatchSize(Queue<T> batch) => batch.Count;
269+
protected override int GetBatchSize(Queue<T> batch)
270+
{
271+
Debug.Assert(batch is not null);
272+
return batch!.Count;
273+
}
266274

267275
/// <inheritdoc />
268276
[MethodImpl(MethodImplOptions.AggressiveInlining)]
269-
protected override void TrimBatch(Queue<T> batch) => batch!.TrimExcess();
277+
protected override void TrimBatch(Queue<T> batch)
278+
{
279+
Debug.Assert(batch is not null);
280+
batch!.TrimExcess();
281+
}
270282
}
271283

272284
/// <inheritdoc />
@@ -278,17 +290,29 @@ public BatchingChannelReader(ChannelReader<T> source, int batchSize, bool single
278290

279291
/// <inheritdoc />
280292
[MethodImpl(MethodImplOptions.AggressiveInlining)]
281-
protected override void AddBatchItem(List<T> batch, T item) => batch.Add(item);
293+
protected override void AddBatchItem(List<T> batch, T item)
294+
{
295+
Debug.Assert(batch is not null);
296+
batch!.Add(item);
297+
}
282298

283299
/// <inheritdoc />
284300
[MethodImpl(MethodImplOptions.AggressiveInlining)]
285301
protected override List<T> CreateBatch(int capacity) => new(capacity);
286302

287303
/// <inheritdoc />
288304
[MethodImpl(MethodImplOptions.AggressiveInlining)]
289-
protected override int GetBatchSize(List<T> batch) => batch.Count;
305+
protected override int GetBatchSize(List<T> batch)
306+
{
307+
Debug.Assert(batch is not null);
308+
return batch!.Count;
309+
}
290310

291311
/// <inheritdoc />
292312
[MethodImpl(MethodImplOptions.AggressiveInlining)]
293-
protected override void TrimBatch(List<T> batch) => batch!.TrimExcess();
313+
protected override void TrimBatch(List<T> batch)
314+
{
315+
Debug.Assert(batch is not null);
316+
batch!.TrimExcess();
317+
}
294318
}

Open.ChannelExtensions/BufferingChannelReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override ValueTask<bool> WaitToReadAsync(CancellationToken cancellationTo
100100
if (completion.IsCompleted)
101101
{
102102
return completion.IsFaulted
103-
? new ValueTask<bool>(Task.FromException<bool>(completion.Exception))
103+
? new ValueTask<bool>(Task.FromException<bool>(completion.Exception!))
104104
: new ValueTask<bool>(false);
105105
}
106106

@@ -131,7 +131,7 @@ protected virtual async ValueTask<bool> WaitToReadAsyncCore(ValueTask<bool> buff
131131

132132
if (bufferWait.IsCompleted)
133133
{
134-
tokenSource.Cancel();
134+
await tokenSource.CancelAsync().ConfigureAwait(false);
135135
return await bufferWait.ConfigureAwait(false);
136136
}
137137

Open.ChannelExtensions/Extensions.Filter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static partial class Extensions
44
{
5-
class FilteringChannelReader<T> : ChannelReader<T>
5+
sealed class FilteringChannelReader<T> : ChannelReader<T>
66
{
77
public FilteringChannelReader(ChannelReader<T> source, Func<T, bool> predicate)
88
{

Open.ChannelExtensions/Extensions.Join.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static partial class Extensions
44
{
5-
class JoiningChannelReader<TList, T> : BufferingChannelReader<TList, T>
5+
sealed class JoiningChannelReader<TList, T> : BufferingChannelReader<TList, T>
66
where TList : IEnumerable<T>
77
{
88
public JoiningChannelReader(ChannelReader<TList> source, bool singleReader) : base(source, singleReader)
@@ -81,7 +81,8 @@ public static ChannelReader<T> Join<T>(this ChannelReader<List<T>> source, bool
8181
public static ChannelReader<T> Join<T>(this ChannelReader<T[]> source, bool singleReader = false)
8282
=> new JoiningChannelReader<T[], T>(source, singleReader);
8383

84-
#if NETSTANDARD2_1
84+
#if NETSTANDARD2_0
85+
#else
8586
/// <summary>
8687
/// Joins collections of the same type into a single channel reader in the order provided.
8788
/// </summary>
@@ -90,6 +91,8 @@ public static ChannelReader<T> Join<T>(this ChannelReader<T[]> source, bool sing
9091
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
9192
/// <param name="allowSynchronousContinuations">True can reduce the amount of scheduling and markedly improve performance, but may produce unexpected or even undesirable behavior.</param>
9293
/// <returns>A channel reader containing the joined results.</returns>
94+
[SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "For NET STandard 2.1")]
95+
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Potential exception type is too far removed.")]
9396
public static ChannelReader<T> Join<T>(
9497
this ChannelReader<IAsyncEnumerable<T>> source,
9598
bool singleReader = false,

Open.ChannelExtensions/Extensions.ReadConcurrently.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public static Task<long> ReadAllConcurrentlyAsync<T>(this ChannelReader<T> reade
2626
if (maxConcurrency == 1)
2727
return reader.ReadAllAsync(receiver, cancellationToken, true).AsTask();
2828

29+
#pragma warning disable IDE0079 // Remove unnecessary suppression
30+
#pragma warning disable CA2000 // Dispose objects before losing scope
2931
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
32+
#pragma warning restore CA2000 // Dispose objects before losing scope
33+
#pragma warning restore IDE0079 // Remove unnecessary suppression
3034
CancellationToken token = tokenSource.Token;
3135
var readers = new Task<long>[maxConcurrency];
3236
for (int r = 0; r < maxConcurrency; ++r)
@@ -37,11 +41,15 @@ public static Task<long> ReadAllConcurrentlyAsync<T>(this ChannelReader<T> reade
3741
.ContinueWith(t =>
3842
{
3943
tokenSource.Dispose();
44+
#pragma warning disable IDE0079 // Remove unnecessary suppression
45+
#pragma warning disable CA1849 // Call async methods when in an async method
4046
return t.IsFaulted
41-
? Task.FromException<long>(t.Exception)
47+
? Task.FromException<long>(t.Exception!)
4248
: t.IsCanceled
4349
? Task.FromCanceled<long>(token)
4450
: Task.FromResult(t.Result.Sum());
51+
#pragma warning restore CA1849 // Call async methods when in an async method
52+
#pragma warning restore IDE0079 // Remove unnecessary suppression
4553
},
4654
CancellationToken.None,
4755
TaskContinuationOptions.ExecuteSynchronously,
@@ -56,7 +64,7 @@ async Task<long> Read()
5664
}
5765
catch
5866
{
59-
tokenSource.Cancel();
67+
await tokenSource.CancelAsync().ConfigureAwait(false);
6068
throw;
6169
}
6270
}
@@ -251,7 +259,11 @@ public static Task ReadAllConcurrentlyAsEnumerablesAsync<T>(this ChannelReader<T
251259
if (maxConcurrency == 1)
252260
return reader.ReadAllAsEnumerablesAsync(receiver, true, cancellationToken).AsTask();
253261

262+
#pragma warning disable IDE0079 // Remove unnecessary suppression
263+
#pragma warning disable CA2000 // Dispose objects before losing scope
254264
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
265+
#pragma warning restore CA2000 // Dispose objects before losing scope
266+
#pragma warning restore IDE0079 // Remove unnecessary suppression
255267
CancellationToken token = tokenSource.Token;
256268
var readers = new Task[maxConcurrency];
257269
for (int r = 0; r < maxConcurrency; ++r)
@@ -260,14 +272,14 @@ public static Task ReadAllConcurrentlyAsEnumerablesAsync<T>(this ChannelReader<T
260272
return Task
261273
.WhenAll(readers)
262274
.ContinueWith(t =>
263-
{
264-
tokenSource.Dispose();
265-
return t.IsFaulted
266-
? Task.FromException(t.Exception)
267-
: t.IsCanceled
268-
? Task.FromCanceled(token)
269-
: Task.CompletedTask;
270-
},
275+
{
276+
tokenSource.Dispose();
277+
return t.IsFaulted
278+
? Task.FromException(t.Exception!)
279+
: t.IsCanceled
280+
? Task.FromCanceled(token)
281+
: Task.CompletedTask;
282+
},
271283
CancellationToken.None,
272284
TaskContinuationOptions.ExecuteSynchronously,
273285
TaskScheduler.Current)
@@ -281,7 +293,7 @@ async Task Read()
281293
}
282294
catch
283295
{
284-
tokenSource.Cancel();
296+
await tokenSource.CancelAsync().ConfigureAwait(false);
285297
throw;
286298
}
287299
}

Open.ChannelExtensions/Extensions.Transform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static partial class Extensions
44
{
5-
class TransformingChannelReader<T, TResult> : ChannelReader<TResult>
5+
sealed class TransformingChannelReader<T, TResult> : ChannelReader<TResult>
66
{
77
public TransformingChannelReader(ChannelReader<T> source, Func<T, TResult> transform)
88
{

0 commit comments

Comments
 (0)