From c3970bd64eb409c60cca9224df7bf2235adf9376 Mon Sep 17 00:00:00 2001 From: KristofferStrube Date: Wed, 31 Jan 2024 20:23:32 +0100 Subject: [PATCH] Updated OscillatorTypeConverter to support reading. --- .../Converters/OscillatorTypeConverter.cs | 10 +++++++++- .../Options/OscillatorType.cs | 10 +++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/KristofferStrube.Blazor.WebAudio/Converters/OscillatorTypeConverter.cs b/src/KristofferStrube.Blazor.WebAudio/Converters/OscillatorTypeConverter.cs index 1818a89..a0277fe 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Converters/OscillatorTypeConverter.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Converters/OscillatorTypeConverter.cs @@ -7,7 +7,15 @@ internal class OscillatorTypeConverter : JsonConverter { public override OscillatorType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(); + return reader.GetString() switch + { + "sine" => OscillatorType.Sine, + "square" => OscillatorType.Square, + "sawtooth" => OscillatorType.Sawtooth, + "triangle" => OscillatorType.Triangle, + "custom" => OscillatorType.Custom, + var value => throw new ArgumentException($"Value '{value}' was not a valid {nameof(OscillatorType)}."), + }; } public override void Write(Utf8JsonWriter writer, OscillatorType value, JsonSerializerOptions options) diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/OscillatorType.cs b/src/KristofferStrube.Blazor.WebAudio/Options/OscillatorType.cs index e55185b..7f13fc2 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/OscillatorType.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/OscillatorType.cs @@ -11,23 +11,23 @@ namespace KristofferStrube.Blazor.WebAudio; public enum OscillatorType { /// - /// A sine wave + /// A sine wave. /// Sine, /// - /// A square wave of duty period 0.5 + /// A square wave of duty period 0.5. /// Square, /// - /// A sawtooth wave + /// A sawtooth wave. /// Sawtooth, /// - /// A triangle wave + /// A triangle wave. /// Triangle, /// - /// A custom periodic wave + /// A custom periodic wave. /// Custom } \ No newline at end of file