Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netstandard2.0 support #531

Merged
merged 2 commits into from
Jun 28, 2024
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://github.com/ardalis/SmartEnum</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TargetFrameworks>net7.0;net6.0;net8.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;net8.0;netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>8.0.0</Version>
Expand All @@ -35,4 +35,4 @@
up $(IsStableBuild) automatically; property is also used to control prerelease branding.
-->
</PropertyGroup>
</Project>
</Project>
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,7 @@ Install-Package Ardalis.SmartEnum.Dapper

## Version

The latest version of the package supports .NET 7. If you don't need or aren't yet ready to move to .NET 7 or later, you should install the previous stable version, [Ardalis.SmartEnum 2.1](https://www.nuget.org/packages/Ardalis.SmartEnum/2.1.0).

Example package manager command:

```
Install-Package Ardalis.SmartEnum -Version 2.1.0
```
The latest version of the package supports .NET 8 and NetStandard 2.0.

## Usage

Expand Down
23 changes: 16 additions & 7 deletions benchmarks/SmartEnum.Benchmarks/FromNameBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ public class FromNameBenchmarks
////////////////////////////////////////////////////////////////////////////////
// Enum

private static TestEnum ParseTestEnum(string value, bool ignoreCase = false)
{
#if NETSTANDARD2_0
return (TestEnum)Enum.Parse(typeof(TestEnum), value, ignoreCase);
#else
return Enum.Parse<TestEnum>(value, ignoreCase);
#endif
}

[Benchmark]
public TestEnum Enum_FromName_One() => Enum.Parse<TestEnum>("One");
public TestEnum Enum_FromName_One() => ParseTestEnum("One");

[Benchmark]
public TestEnum Enum_FromName_Ten() => Enum.Parse<TestEnum>("Ten");
public TestEnum Enum_FromName_Ten() => ParseTestEnum("Ten");

[Benchmark]
public TestEnum Enum_FromName_Invalid()
{
try
{
return Enum.Parse<TestEnum>("Invalid");
return ParseTestEnum("Invalid");
}
catch (Exception)
{
Expand All @@ -32,18 +41,18 @@ public TestEnum Enum_FromName_Invalid()
}

[Benchmark]
public TestEnum Enum_FromName_one_IgnoreCase() => Enum.Parse<TestEnum>("one", true);
public TestEnum Enum_FromName_one_IgnoreCase() => ParseTestEnum("one", true);

[Benchmark]
public TestEnum Enum_FromName_ten_IgnoreCase() => Enum.Parse<TestEnum>("ten", true);
public TestEnum Enum_FromName_ten_IgnoreCase() => ParseTestEnum("ten", true);


[Benchmark]
public TestEnum Enum_FromName_Invalid_IgnoreCase()
{
try
{
return Enum.Parse<TestEnum>("Invalid", true);
return ParseTestEnum("Invalid", true);
}
catch (Exception)
{
Expand Down Expand Up @@ -229,4 +238,4 @@ public TestSmartEnum SmartEnum_TryFromName_Invalid_IgnoreCase()
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.0'">
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/SmartEnum/SmartEnum.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</None>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.0'">
<PackageReference Include="System.ComponentModel.Annotations" />
</ItemGroup>
</Project>
Loading