1.3 Orientation value type
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
src/FrameProcessor/Domain/Orientation.cs
Normal file
34
src/FrameProcessor/Domain/Orientation.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace FrameProcessor.Domain;
|
||||
|
||||
[JsonConverter(typeof(OrientationJsonConverter))]
|
||||
public enum Orientation
|
||||
{
|
||||
Landscape,
|
||||
Portrait,
|
||||
}
|
||||
|
||||
internal sealed class OrientationJsonConverter : JsonConverter<Orientation>
|
||||
{
|
||||
public override Orientation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var s = reader.GetString();
|
||||
return s switch
|
||||
{
|
||||
"landscape" => Orientation.Landscape,
|
||||
"portrait" => Orientation.Portrait,
|
||||
_ => throw new JsonException(
|
||||
$"'{s}' is not a valid orientation. Expected 'landscape' or 'portrait'."),
|
||||
};
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Orientation value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value switch
|
||||
{
|
||||
Orientation.Landscape => "landscape",
|
||||
Orientation.Portrait => "portrait",
|
||||
_ => throw new JsonException($"Unknown orientation: {value}."),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user