From a1b90a9f1f2e04683a9362c705dbb6aa266b9d18 Mon Sep 17 00:00:00 2001 From: Steven Ryland Date: Wed, 22 May 2024 11:24:06 -0700 Subject: [PATCH] Refactor parsing string as enum --- .../Types/OutputStateChanged.cs | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/obs-websocket-dotnet/Types/OutputStateChanged.cs b/obs-websocket-dotnet/Types/OutputStateChanged.cs index 7df9d85..f3fa88b 100644 --- a/obs-websocket-dotnet/Types/OutputStateChanged.cs +++ b/obs-websocket-dotnet/Types/OutputStateChanged.cs @@ -35,29 +35,11 @@ public OutputState State { return state.Value; } - switch (StateStr) + if (!Enum.TryParse(StateStr, ignoreCase: true, out OutputState stateTmp)) { - case "OBS_WEBSOCKET_OUTPUT_STARTING": - state = OutputState.OBS_WEBSOCKET_OUTPUT_STARTING; - break; - case "OBS_WEBSOCKET_OUTPUT_STARTED": - state = OutputState.OBS_WEBSOCKET_OUTPUT_STARTED; - break; - case "OBS_WEBSOCKET_OUTPUT_STOPPING": - state = OutputState.OBS_WEBSOCKET_OUTPUT_STOPPING; - break; - case "OBS_WEBSOCKET_OUTPUT_STOPPED": - state = OutputState.OBS_WEBSOCKET_OUTPUT_STOPPED; - break; - case "OBS_WEBSOCKET_OUTPUT_PAUSED": - state = OutputState.OBS_WEBSOCKET_OUTPUT_PAUSED; - break; - case "OBS_WEBSOCKET_OUTPUT_RESUMED": - state = OutputState.OBS_WEBSOCKET_OUTPUT_RESUMED; - break; - default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException($"Couldn't parse '{StateStr}' as {nameof(OutputState)}"); } + state = stateTmp; return state.Value; }