Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=crlf
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "9.0.320",
"rollForward": "latestPatch",
"allowPrerelease": false
}
}
45 changes: 7 additions & 38 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tab_width = 4

# New line preferences
end_of_line = crlf
insert_final_newline = false
insert_final_newline = true

#### .NET Code Actions ####

Expand Down Expand Up @@ -271,41 +271,10 @@ dotnet_naming_style.begins_with__.required_suffix =
dotnet_naming_style.begins_with__.word_separator =
dotnet_naming_style.begins_with__.capitalization = camel_case

[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = false:silent
dotnet_style_prefer_inferred_anonymous_type_member_names = false:silent
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_readonly_field = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_code_quality_unused_parameters = non_public:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
# API shape rules intentionally not applied: CA1040 and CA1034 are valid in this library.
dotnet_diagnostic.CA1040.severity = none
dotnet_diagnostic.CA1034.severity = none
dotnet_diagnostic.CA1034.severity = none

[**/*Tests.cs]
# xUnit method names use underscores to describe scenario and expected result.
dotnet_diagnostic.CA1707.severity = none
8 changes: 8 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>Recommended</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions src/WeakEvent.Tests/WeakEventGenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task OpenInstanceHandler_IsInvoked()
Assert.Equal(1, subscriber.CallCount);
}

private class OpenInstanceSubscriber
private sealed class OpenInstanceSubscriber
{
public int CallCount { get; private set; }

Expand Down Expand Up @@ -287,12 +287,12 @@ private static void CollectGarbage()
}
}

private class GenericSubscriber(Action onEvent)
private sealed class GenericSubscriber(Action onEvent)
{
private readonly Action _onEvent = onEvent;

public void Handler(string _) => _onEvent();
}

private sealed class TestException : Exception;
}
}
4 changes: 2 additions & 2 deletions src/WeakEvent.Tests/WeakEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static WeakEventHandler CreateWeakSubscriber()
// 'subscriber' goes out of scope after this method.
}

private class Subscriber
private sealed class Subscriber
{
public bool Invoked { get; private set; }
public bool ThrowIfInvoked { get; init; }
Expand Down Expand Up @@ -150,4 +150,4 @@ private static void CollectGarbage()
GC.WaitForPendingFinalizers();
}
}
}
}
8 changes: 5 additions & 3 deletions src/WeakEvent.Tests/WeakEventLockingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ async Task firstHandler()
callCount++;
}

void secondHandler() => callCount++;
void secondHandler()
{
callCount++;
}

e.Subscribe(firstHandler);
var firstPublication = e.PublishAsync();
Expand All @@ -51,5 +54,4 @@ async Task firstHandler()
await e.PublishAsync();
Assert.Equal(3, callCount);
}

}
}
4 changes: 2 additions & 2 deletions src/WeakEvent.Tests/WeakEventNonGenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ private static void CollectGarbage()
}
}

private class NonGenericSubscriber(Action onEvent)
private sealed class NonGenericSubscriber(Action onEvent)
{
private readonly Action _onEvent = onEvent;

public void Handler() => _onEvent();
}
}
}
2 changes: 1 addition & 1 deletion src/WeakEvent/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("WeakEvent.Tests")]
[assembly: InternalsVisibleTo("WeakEvent.Tests")]
2 changes: 1 addition & 1 deletion src/WeakEvent/WeakEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ public void Subscribe(Func<CancellationToken, Task> handler)
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
public Task PublishAsync(CancellationToken cancellationToken = default)
=> _core.PublishAsync<object?>(null, cancellationToken);
}
}
4 changes: 3 additions & 1 deletion src/WeakEvent/WeakEventCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public int SubscriberCount
{
get
{
// ReSharper disable once InconsistentlySynchronizedField
var handlers = Volatile.Read(ref _handlers);
var count = 0;

Expand Down Expand Up @@ -115,6 +116,7 @@ public async Task PublishAsync<TEvent>(

private WeakEventHandler[] GetLiveSnapshot()
{
// ReSharper disable once InconsistentlySynchronizedField
var handlers = Volatile.Read(ref _handlers);
var liveCount = 0;

Expand Down Expand Up @@ -157,4 +159,4 @@ private WeakEventHandler[] GetLiveSnapshot()

return liveHandlers;
}
}
}
Loading