-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add support for line endings being configurable.
closes #935
- Loading branch information
Showing
7 changed files
with
104 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
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,36 @@ | ||
namespace CSharpier.Cli.Options; | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
internal class CaseInsensitiveEnumConverter<TEnum> : JsonConverter<TEnum> | ||
where TEnum : struct | ||
{ | ||
public override TEnum Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
if (reader.TokenType != JsonTokenType.String) | ||
{ | ||
throw new JsonException( | ||
$"Expected a string for enum parsing, but got {reader.TokenType}." | ||
); | ||
} | ||
|
||
var enumText = reader.GetString(); | ||
if (Enum.TryParse(enumText, true, out TEnum result)) | ||
{ | ||
return result; | ||
} | ||
|
||
throw new JsonException($"Unable to parse '{enumText}' to enum of type {typeof(TEnum)}."); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) | ||
{ | ||
var enumText = value.ToString(); | ||
writer.WriteStringValue(enumText); | ||
} | ||
} |
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