-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7eef138
commit 798b656
Showing
7 changed files
with
77 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.Serialization; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Mindee.Input | ||
{ | ||
/// <summary> | ||
/// Priority for a workflow execution. | ||
/// </summary> | ||
public enum ExecutionPriority | ||
{ | ||
/// <summary> | ||
/// Low priority. | ||
/// </summary> | ||
[EnumMember(Value = "low")] Low, | ||
|
||
/// <summary> | ||
/// Medium priority. | ||
/// </summary> | ||
[EnumMember(Value = "medium")] Medium, | ||
|
||
/// <summary> | ||
/// Hight priority. | ||
/// </summary> | ||
[EnumMember(Value = "high")] High | ||
} | ||
|
||
/// <summary> | ||
/// Deserializer for the ExecutionPriority enum. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public class StringEnumConverter<T> : JsonConverter<T> where T : struct, Enum | ||
{ | ||
/// <summary> | ||
/// Read a JSON value. | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <param name="typeToConvert"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
string value = reader.GetString(); | ||
return Enum.TryParse<T>(value, true, out var result) ? result : default; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a JSON value. | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="options"></param> | ||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString().ToLower()); | ||
} | ||
} | ||
} |
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