-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added SmartFlagEnum Functionality * Added AutoFixture Support for SmarFlagEnum Type * SmartFlagEnum 1.0. Serialization and AutoFixture Utilities and UnitTests Complete. * Return all flags for underlying type MaxValue When FromValue() is called on a SmartFlagEnum with the corresponding MaxValue of the base tyoe as the value agrument, a list of all defined enum values is returned. This is similar to passing negative one. * Pulled In Upstream Changes and Resolved Conflicts, Files Moved To New Folder Structure * Missing nuget packages for integration projects (#62) * current progress * Move test project to solution and create Directory.Build.props files to simplify the configuration process * Set up CI with Azure Pipelines [skip ci] * Remove redundant PackageId from Directory.Build.props * Fix LangVersion property * Fix unit test project missing source project references * Update test project path * Update azure-pipelines.yml for Azure Pipelines * Remove duplicate tasks * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Remove Benchmarks from pack process by ading <GeneratePackageOnBuild>false</GeneratePackageOnBuild> * Make protram and main method public to avoid error CS5001 on azure pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Reorder project structure -Bring solution to the root path -Create benchmarks folder and move project -Move test projects from src/test to test -Reorder projects inside solutions -Craete Directory.Build.props for tests projects and propagate code coverage and commons nuget packages. -Update azure .ylm pipeline to produce code coverage diagrams and result * Fix solution items Co-authored-by: Steve Smith <steve@kentsmiths.com> Co-authored-by: Daniel Meza <dmeza@speedsol.com> * Bump MessagePack from 1.7.3.4 to 1.9.11 in /src/SmartEnum.MessagePack (#68) Bumps [MessagePack](https://github.com/neuecc/MessagePack-CSharp) from 1.7.3.4 to 1.9.11. - [Release notes](https://github.com/neuecc/MessagePack-CSharp/releases) - [Commits](MessagePack-CSharp/MessagePack-CSharp@v1.7.3.4...v1.9.11) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Pulled In Upstream Changes and Resolved Conflicts, Files Moved To New Folder Structure * Merge branch 'master' into smart-flag-enum * adding System.Text.Json converters for SmartFlagEnum Co-authored-by: Steve Smith <steve@kentsmiths.com> Co-authored-by: AFMHorizon <52022448+AFM-Horizon@users.noreply.github.com> Co-authored-by: Suhaib <suhaibhasan@gmail.com> Co-authored-by: Daniel Meza <daniel.meza2011@gmail.com> Co-authored-by: Daniel Meza <dmeza@speedsol.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f1ee0a6
commit 674d281
Showing
67 changed files
with
4,530 additions
and
32 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
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,3 +1,5 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Ardalis.SmartEnum.JsonNet | ||
{ | ||
using Newtonsoft.Json; | ||
|
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,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlTypes; | ||
using System.Linq; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
|
||
namespace Ardalis.SmartEnum.JsonNet | ||
{ | ||
public class SmartFlagEnumNameConverter<TEnum, TValue> : JsonConverter<TEnum> | ||
where TEnum : SmartFlagEnum<TEnum, TValue> | ||
where TValue : struct, IComparable<TValue>, IEquatable<TValue> | ||
{ | ||
public override bool CanRead => true; | ||
|
||
public override bool CanWrite => true; | ||
|
||
public override TEnum ReadJson(JsonReader reader, Type objectType, TEnum existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
switch (reader.TokenType) | ||
{ | ||
case JsonToken.String: | ||
return GetFromName((string)reader.Value); | ||
|
||
default: | ||
throw new JsonSerializationException($"Unexpected token {reader.TokenType} when parsing a smart flag enum."); | ||
} | ||
|
||
TEnum GetFromName(string name) | ||
{ | ||
try | ||
{ | ||
return SmartFlagEnum<TEnum, TValue>.FromName(name, false).FirstOrDefault(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new JsonSerializationException($"Error converting value '{name}' to a smart flag enum.", ex); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="serializer"></param> | ||
public override void WriteJson(JsonWriter writer, TEnum value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
writer.WriteNull(); | ||
else | ||
writer.WriteValue(value.Name); | ||
} | ||
} | ||
} |
Oops, something went wrong.