Skip to content

Commit 219cc1b

Browse files
authored
Add netstandard2.0 support (#531)
* feat: Build in netstandard2.0 to support .Net Framework * docs: Update version description
1 parent c3f8e56 commit 219cc1b

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageProjectUrl>https://github.com/ardalis/SmartEnum</PackageProjectUrl>
1010
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1111
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12-
<TargetFrameworks>net7.0;net6.0;net8.0;netstandard2.1</TargetFrameworks>
12+
<TargetFrameworks>net7.0;net6.0;net8.0;netstandard2.0</TargetFrameworks>
1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1515
<Version>8.0.0</Version>
@@ -35,4 +35,4 @@
3535
up $(IsStableBuild) automatically; property is also used to control prerelease branding.
3636
-->
3737
</PropertyGroup>
38-
</Project>
38+
</Project>

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,7 @@ Install-Package Ardalis.SmartEnum.Dapper
8989

9090
## Version
9191

92-
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).
93-
94-
Example package manager command:
95-
96-
```
97-
Install-Package Ardalis.SmartEnum -Version 2.1.0
98-
```
92+
The latest version of the package supports .NET 8 and NetStandard 2.0.
9993

10094
## Usage
10195

benchmarks/SmartEnum.Benchmarks/FromNameBenchmarks.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ public class FromNameBenchmarks
1212
////////////////////////////////////////////////////////////////////////////////
1313
// Enum
1414

15+
private static TestEnum ParseTestEnum(string value, bool ignoreCase = false)
16+
{
17+
#if NETSTANDARD2_0
18+
return (TestEnum)Enum.Parse(typeof(TestEnum), value, ignoreCase);
19+
#else
20+
return Enum.Parse<TestEnum>(value, ignoreCase);
21+
#endif
22+
}
23+
1524
[Benchmark]
16-
public TestEnum Enum_FromName_One() => Enum.Parse<TestEnum>("One");
25+
public TestEnum Enum_FromName_One() => ParseTestEnum("One");
1726

1827
[Benchmark]
19-
public TestEnum Enum_FromName_Ten() => Enum.Parse<TestEnum>("Ten");
28+
public TestEnum Enum_FromName_Ten() => ParseTestEnum("Ten");
2029

2130
[Benchmark]
2231
public TestEnum Enum_FromName_Invalid()
2332
{
2433
try
2534
{
26-
return Enum.Parse<TestEnum>("Invalid");
35+
return ParseTestEnum("Invalid");
2736
}
2837
catch (Exception)
2938
{
@@ -32,18 +41,18 @@ public TestEnum Enum_FromName_Invalid()
3241
}
3342

3443
[Benchmark]
35-
public TestEnum Enum_FromName_one_IgnoreCase() => Enum.Parse<TestEnum>("one", true);
44+
public TestEnum Enum_FromName_one_IgnoreCase() => ParseTestEnum("one", true);
3645

3746
[Benchmark]
38-
public TestEnum Enum_FromName_ten_IgnoreCase() => Enum.Parse<TestEnum>("ten", true);
47+
public TestEnum Enum_FromName_ten_IgnoreCase() => ParseTestEnum("ten", true);
3948

4049

4150
[Benchmark]
4251
public TestEnum Enum_FromName_Invalid_IgnoreCase()
4352
{
4453
try
4554
{
46-
return Enum.Parse<TestEnum>("Invalid", true);
55+
return ParseTestEnum("Invalid", true);
4756
}
4857
catch (Exception)
4958
{
@@ -229,4 +238,4 @@ public TestSmartEnum SmartEnum_TryFromName_Invalid_IgnoreCase()
229238
}
230239

231240
}
232-
}
241+
}

src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
1515
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
1616
</PropertyGroup>
17-
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.1'">
17+
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.0'">
1818
<PackageReference Include="System.Text.Json" />
1919
</ItemGroup>
2020
<ItemGroup>

src/SmartEnum/SmartEnum.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</None>
3535
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
3636
</ItemGroup>
37-
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.1'">
37+
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.0'">
3838
<PackageReference Include="System.ComponentModel.Annotations" />
3939
</ItemGroup>
4040
</Project>

0 commit comments

Comments
 (0)