-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/nuget/MessagePack-2.5.140
- Loading branch information
Showing
33 changed files
with
633 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: publish SmartEnum.GuardClauses to nuget | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main # Your default release branch | ||
paths: | ||
- 'src/SmartEnum.GuardClauses/**' | ||
jobs: | ||
publish: | ||
name: list SmartEnum.GuardClauses on nuget.org | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
# Required for a specific dotnet version that doesn't come with ubuntu-latest / windows-latest | ||
# Visit bit.ly/2synnZl to see the list of SDKs that are pre-installed with ubuntu-latest / windows-latest | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: | | ||
6.0.x | ||
7.0.x | ||
8.0.x | ||
# Publish | ||
- name: publish on version change | ||
uses: alirezanet/[email protected] | ||
with: | ||
PROJECT_FILE_PATH: src/SmartEnum.GuardClauses/SmartEnum.GuardClauses.csproj # Relative to repository root | ||
VERSION_FILE_PATH: Directory.Build.props # Filepath with version info, relative to repository root. Defaults to project file | ||
VERSION_REGEX: <Version>(.*)<\/Version> # Regex pattern to extract version info in a capturing group | ||
TAG_COMMIT: true # Flag to enable / disable git tagging | ||
TAG_FORMAT: SmartEnumGuardClauses-v* # Format of the git tag, [*] gets replaced with version | ||
NUGET_KEY: ${{secrets.NUGET_API_KEY}} # nuget.org API key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
namespace Ardalis.SmartEnum.Dapper | ||
{ | ||
//using global::Dapper; | ||
using System; | ||
|
||
/// <summary> | ||
|
66 changes: 66 additions & 0 deletions
66
src/SmartEnum.GuardClauses/GuardAgainstSmartEnumOutOfRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Ardalis.GuardClauses; | ||
using System; | ||
|
||
namespace Ardalis.SmartEnum.GuardClauses | ||
{ | ||
/// <summary> | ||
/// Provides guard clauses to ensure input values are valid instances of a specified SmartEnum. | ||
/// </summary> | ||
public static class GuardAgainstSmartEnumOutOfRange | ||
{ | ||
/// <summary> | ||
/// Throws a<see cref="SmartEnumNotFoundException" /> or a custom<see cref="Exception" /> | ||
/// if <paramref name="input"/> is not a valid <see cref="SmartEnum{TEnum}"/> value. | ||
/// </summary> | ||
/// <typeparam name="TEnum">The type of the smart enum.</typeparam> | ||
/// <param name="guardClause">The guard clause interface.</param> | ||
/// <param name="input">The value to check against the smart enum values.</param> | ||
/// <param name="message">Optional. Custom error message to pass to <see cref="SmartEnumNotFoundException"/>.</param> | ||
/// <param name="exceptionCreator">Optional. A function that creates a custom exception.</param> | ||
/// <returns>The valid <see cref="SmartEnum{TEnum}"/> value <paramref name="input" />.</returns> | ||
/// <exception cref="SmartEnumNotFoundException">Thrown when <paramref name="input" /> | ||
/// is not a valid enum value, and no custom exception is provided.</exception> | ||
/// <exception cref="Exception">Thrown when a custom exception is provided by <paramref name="exceptionCreator" />.</exception> | ||
public static TEnum SmartEnumOutOfRange<TEnum>( | ||
this IGuardClause guardClause, | ||
int input, | ||
string message = null, | ||
Func<Exception> exceptionCreator = null) | ||
where TEnum : SmartEnum<TEnum> | ||
{ | ||
return guardClause.SmartEnumOutOfRange<TEnum, int>(input, message, exceptionCreator); | ||
} | ||
|
||
/// <summary> | ||
/// Throws a <see cref="SmartEnumNotFoundException"/> or a custom <see cref="Exception"/> | ||
/// if <paramref name="input"/> is not a valid <see cref="SmartEnum{TEnum, TValue}"/> value. | ||
/// </summary> | ||
/// <typeparam name="TEnum">The type of the smart enum.</typeparam> | ||
/// <typeparam name="TValue">The type of the value that the smart enum uses.</typeparam> | ||
/// <param name="guardClause">The guard clause interface.</param> | ||
/// <param name="input">The value to check against the smart enum values.</param> | ||
/// <param name="message">Optional. Custom error message to pass to <see cref="SmartEnumNotFoundException"/>.</param> | ||
/// <param name="exceptionCreator">Optional. A function that creates a custom exception.</param> | ||
/// <returns>The valid enum value <typeparamref name="TEnum"/> corresponding to <paramref name="input"/>.</returns> | ||
/// <exception cref="SmartEnumNotFoundException">Thrown when <paramref name="input"/> | ||
/// is not a valid enum value and no custom exception is provided.</exception> | ||
/// <exception cref="Exception">Thrown when a custom exception | ||
/// is provided by <paramref name="exceptionCreator"/>.</exception> | ||
public static TEnum SmartEnumOutOfRange<TEnum, TValue>( | ||
this IGuardClause guardClause, | ||
TValue input, | ||
string message = null, | ||
Func<Exception> exceptionCreator = null) | ||
where TEnum : SmartEnum<TEnum, TValue> | ||
where TValue : IEquatable<TValue>, IComparable<TValue> | ||
{ | ||
if (SmartEnum<TEnum, TValue>.TryFromValue(input, out TEnum result)) | ||
{ | ||
return result; | ||
} | ||
|
||
var exceptionMessage = message ?? $"The value '{input}' is not a valid {typeof(TEnum).Name}."; | ||
throw exceptionCreator?.Invoke() ?? new SmartEnumNotFoundException(exceptionMessage); | ||
} | ||
} | ||
} |
Oops, something went wrong.