Skip to content

Commit

Permalink
#515 Optimise dependencies to remove polyfil (#516)
Browse files Browse the repository at this point in the history
* #515 make STJ only included for net standard

* Moved to global package refs & add suppressions

* Make System.ComponentModel.Annotations oonly for net std

* Styling fixes.

---------

Co-authored-by: Steve Smith <[email protected]>
  • Loading branch information
thompson-tomo and ardalis authored Apr 28, 2024
1 parent 7396d73 commit c3f8e56
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 117 deletions.
7 changes: 5 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="protobuf-net" Version="3.2.26" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.17.0.82934" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.2" />
<PackageVersion Include="Utf8Json" Version="1.3.7" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="9.17.0.82934" PrivateAssets="All" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions benchmarks/SmartEnum.Benchmarks/EqualsBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Ardalis.SmartEnum.Benchmarks
{
using BenchmarkDotNet.Attributes;
using System.Diagnostics.CodeAnalysis;

[Config(typeof(Config))]
[SuppressMessage("Major Bug", "S1764:Identical expressions should not be used on both sides of operators", Justification = "<Pending>")]
public class EqualsBenchmarks
{
////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/SmartEnum.Benchmarks/SerializationBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Ardalis.SmartEnum.Benchmarks
{
using System.Diagnostics.CodeAnalysis;
using System.IO;
using BenchmarkDotNet.Attributes;

Expand Down Expand Up @@ -68,6 +69,7 @@ public sealed class TestSmartEnumValueClass
static Stream valueProtoBufDeserializeStream;

[GlobalSetup]
[SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "<Pending>")]
public void GlobalSetup()
{
global::Utf8Json.Resolvers.CompositeResolver.Register(
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/SmartEnum.Benchmarks/SwitchBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Ardalis.SmartEnum.Benchmarks
{
using System;
using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;

[Config(typeof(Config))]
[SuppressMessage("Major Bug", "S2583:Conditionally executed code should be reachable", Justification = "<Pending>")]
[SuppressMessage("Major Code Smell", "S112:General or reserved exceptions should never be thrown", Justification = "<Pending>")]
public class SwitchBenchmarks
{
////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/SmartEnum.Benchmarks/TestEnums.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Diagnostics.CodeAnalysis;

namespace Ardalis.SmartEnum.Benchmarks
{
////////////////////////////////////////////////////////////////////////////////
// Enum

[global::ProtoBuf.ProtoContract]
[SuppressMessage("Minor Code Smell", "S2344:Enumeration type names should not have \"Flags\" or \"Enum\" suffixes", Justification = "<Pending>")]
public enum TestEnum
{
[global::ProtoBuf.ProtoEnum]
Expand Down
2 changes: 0 additions & 2 deletions src/SmartEnum.AutoFixture/SmartEnum.AutoFixture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down
1 change: 0 additions & 1 deletion src/SmartEnum.Dapper/DapperSmartEnum.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Ardalis.SmartEnum.Dapper
{
//using global::Dapper;
using System;

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/SmartEnum.JsonNet/SmartEnum.JsonNet.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Ardalis.SmartEnum.JsonNet</PackageId>
<Title>Ardalis.SmartEnum.JsonNet</Title>
Expand All @@ -15,8 +15,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down
2 changes: 0 additions & 2 deletions src/SmartEnum.MessagePack/SmartEnum.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MessagePack" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down
13 changes: 6 additions & 7 deletions src/SmartEnum.ModelBinding/SmartEnumModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
if (methodInfo.Name == "FromName")
{
ParameterInfo[] methodsParams = methodInfo.GetParameters();
if (methodsParams.Length == 2)
if (methodsParams.Length == 2 &&
methodsParams[0].ParameterType == typeof(string) &&
methodsParams[1].ParameterType == typeof(bool))
{
if (methodsParams[0].ParameterType == typeof(string) && methodsParams[1].ParameterType == typeof(bool))
{
var enumObj = methodInfo.Invoke(null, new object[] { enumKeyName, true });
bindingContext.Result = ModelBindingResult.Success(enumObj);
return Task.CompletedTask;
}
var enumObj = methodInfo.Invoke(null, new object[] { enumKeyName, true });
bindingContext.Result = ModelBindingResult.Success(enumObj);
return Task.CompletedTask;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/SmartEnum.ProtoBufNet/SmartEnum.ProtoBufNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="protobuf-net" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down
50 changes: 24 additions & 26 deletions src/SmartEnum.SystemTextJson/SmartEnum.SystemTextJson.csproj
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Ardalis.SmartEnum.SystemTextJson</PackageId>
<Title>Ardalis.SmartEnum.SystemTextJson</Title>
<Description>System.Text.Json (de)serialization support for Ardalis.SmartEnum.</Description>
<Summary>System.Text.Json (de)serialization support for Ardalis.SmartEnum.</Summary>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>enum;smartenum;netstandard2.0;json;system.text.json;converter</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes>Updating to net7.</PackageReleaseNotes>
<AssemblyName>Ardalis.SmartEnum.SystemTextJson</AssemblyName>
<RootNamespace>Ardalis.SmartEnum.SystemTextJson</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartEnum\SmartEnum.csproj" />
</ItemGroup>
<PropertyGroup>
<PackageId>Ardalis.SmartEnum.SystemTextJson</PackageId>
<Title>Ardalis.SmartEnum.SystemTextJson</Title>
<Description>System.Text.Json (de)serialization support for Ardalis.SmartEnum.</Description>
<Summary>System.Text.Json (de)serialization support for Ardalis.SmartEnum.</Summary>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>enum;smartenum;netstandard2.0;json;system.text.json;converter</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes>Updating to net7.</PackageReleaseNotes>
<AssemblyName>Ardalis.SmartEnum.SystemTextJson</AssemblyName>
<RootNamespace>Ardalis.SmartEnum.SystemTextJson</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netStandard2.1'">
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<None Include="$(SolutionDir)img\icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartEnum\SmartEnum.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Ardalis.SmartEnum.Exceptions
{
/// <summary>
///
///
/// </summary>
[Serializable]
[SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "<Pending>")]
public class InvalidFlagEnumValueParseException : Exception
{
/// <summary>
Expand All @@ -16,7 +18,7 @@ public InvalidFlagEnumValueParseException() : base()
}

/// <summary>
/// Initializes a new instance of the <see cref="InvalidFlagEnumValueParseException"/> class with a user specified error <paramref name="message"/>.
/// Initializes a new instance of the <see cref="InvalidFlagEnumValueParseException"/> class with a user specified error <paramref name="message"/>.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public InvalidFlagEnumValueParseException(string message) : base(message)
Expand All @@ -28,7 +30,7 @@ public InvalidFlagEnumValueParseException(string message) : base(message)
/// and a wrapped <paramref name="innerException"/> that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException"></param> The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// <param name="innerException"></param> The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// the current exception is raised in a <c>catch</c> block that handles the inner exception.
public InvalidFlagEnumValueParseException(string message, Exception innerException) : base(message, innerException)
{
Expand Down
6 changes: 4 additions & 2 deletions src/SmartEnum/Exceptions/NegativeValueArgumentException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace Ardalis.SmartEnum.Exceptions
Expand All @@ -8,6 +9,7 @@ namespace Ardalis.SmartEnum.Exceptions
/// The exception that is thrown when a negative value is provided as an argument value.
/// </summary>
[Serializable]
[SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "<Pending>")]
public class NegativeValueArgumentException : ArgumentException
{
/// <summary>
Expand All @@ -26,12 +28,12 @@ public NegativeValueArgumentException(string message) : base(message)
}

/// <summary>
/// Initializes a new instance of the <see cref="NegativeValueArgumentException"/> class with a specified error message and
/// Initializes a new instance of the <see cref="NegativeValueArgumentException"/> class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// the current exception is raised in a <c>catch</c> block that handles the inner exception.
/// </param>
public NegativeValueArgumentException(string message, Exception innerException) : base(message, innerException)
Expand Down
6 changes: 4 additions & 2 deletions src/SmartEnum/Exceptions/SmartEnumNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace Ardalis.SmartEnum
{
using System;
using System.Diagnostics.CodeAnalysis;

/// <summary>
/// The exception that is thrown when a item is not found.
/// </summary>
[Serializable]
[SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "<Pending>")]
public class SmartEnumNotFoundException : Exception
{
/// <summary>
Expand All @@ -26,12 +28,12 @@ public SmartEnumNotFoundException(string message)
}

/// <summary>
/// Initializes a new instance of the <see cref="SmartEnumNotFoundException"/> class with a specified error message and
/// Initializes a new instance of the <see cref="SmartEnumNotFoundException"/> class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// the current exception is raised in a <c>catch</c> block that handles the inner exception.
/// </param>
public SmartEnumNotFoundException(string message, Exception innerException)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Ardalis.SmartEnum.Exceptions
{
/// <summary>
///
///
/// </summary>
[Serializable]
[SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "<Pending>")]
public class SmartFlagEnumContainsNegativeValueException : Exception
{
/// <summary>
Expand All @@ -16,7 +18,7 @@ public SmartFlagEnumContainsNegativeValueException() : base()
}

/// <summary>
/// Initializes a new instance of the <see cref="SmartFlagEnumContainsNegativeValueException"/> class with a user specified error <paramref name="message"/>.
/// Initializes a new instance of the <see cref="SmartFlagEnumContainsNegativeValueException"/> class with a user specified error <paramref name="message"/>.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public SmartFlagEnumContainsNegativeValueException(string message) : base(message)
Expand All @@ -28,7 +30,7 @@ public SmartFlagEnumContainsNegativeValueException(string message) : base(messag
/// and a wrapped <paramref name="innerException"/> that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException"></param> The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// <param name="innerException"></param> The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// the current exception is raised in a <c>catch</c> block that handles the inner exception.
public SmartFlagEnumContainsNegativeValueException(string message, Exception innerException) : base(message, innerException)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace Ardalis.SmartEnum.Exceptions
Expand All @@ -8,6 +9,7 @@ namespace Ardalis.SmartEnum.Exceptions
/// The exception that is thrown when a <see cref="SmartFlagEnum{TEnum}"/> does not contain consecutive power of two values.
/// </summary>
[Serializable]
[SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "<Pending>")]
public class SmartFlagEnumDoesNotContainPowerOfTwoValuesException : Exception
{
/// <summary>
Expand All @@ -28,12 +30,12 @@ public SmartFlagEnumDoesNotContainPowerOfTwoValuesException(string message)
}

/// <summary>
/// Initializes a new instance of the <see cref="SmartFlagEnumDoesNotContainPowerOfTwoValuesException"/> class with a specified error message and
/// Initializes a new instance of the <see cref="SmartFlagEnumDoesNotContainPowerOfTwoValuesException"/> class with a specified error message and
/// a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference,
/// the current exception is raised in a <c>catch</c> block that handles the inner exception.
/// </param>
public SmartFlagEnumDoesNotContainPowerOfTwoValuesException(string message, Exception innerException)
Expand Down
Loading

0 comments on commit c3f8e56

Please sign in to comment.