Skip to content

Commit

Permalink
.NET Standard 2.0 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seramis committed Feb 19, 2025
1 parent d0386f3 commit 34bada4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- main
paths:
- src/**
workflow_dispatch:

jobs:
build:
Expand All @@ -25,7 +26,6 @@ jobs:
with:
dotnet-version: |
9.x
6.x
- name: Restore dependencies
run: dotnet restore src/WeakEvent.sln
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- src/**
schedule:
- cron: '20 6 * * 5'
workflow_dispatch:

jobs:
analyze:
Expand All @@ -36,7 +37,6 @@ jobs:
with:
dotnet-version: |
9.x
6.x
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
with:
dotnet-version: |
9.x
6.x
- name: 'Get Version'
id: version
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ In the context of Blazor components, this functionality is particularly valuable

## Features

![.NET 9.0](https://img.shields.io/badge/.NET-9.0-brightgreen)
![.NET 6.0](https://img.shields.io/badge/.NET-6.0-brightgreen)
![.NET Standard 2.0](https://img.shields.io/badge/.NET_Standard-2.0-brightgreen)

- **Weak References:** Subscribers are held via weak references, allowing the garbage collector to reclaim them when they are no longer needed.
- **Events With or Without Data:** Use `WeakEvent<TEvent>` when you need to pass event data to subscribers, or `WeakEvent` for simple notifications that don't require additional information.
Expand Down
2 changes: 1 addition & 1 deletion src/WeakEvent.Tests/WeakEvent.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0;net6.0</TargetFrameworks>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
10 changes: 8 additions & 2 deletions src/WeakEvent/WeakEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ public abstract class WeakEventBase
/// <exception cref="ArgumentNullException">Thrown when <paramref name="handler"/> is null.</exception>
protected void Subscribe(Delegate handler)
{
ArgumentNullException.ThrowIfNull(handler);
if (handler is null)
{
throw new ArgumentNullException(nameof(handler));
}

_handlers.Add(new WeakEventHandler(handler));
}
Expand All @@ -172,7 +175,10 @@ protected void Subscribe(Delegate handler)
/// <exception cref="ArgumentNullException">Thrown when <paramref name="handler"/> is null.</exception>
protected bool Unsubscribe(Delegate handler)
{
ArgumentNullException.ThrowIfNull(handler);
if (handler is null)
{
throw new ArgumentNullException(nameof(handler));
}

return _handlers.RemoveAll(weh => weh.Matches(handler)) > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WeakEvent/WeakEvent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net9.0;net6.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down

0 comments on commit 34bada4

Please sign in to comment.