Skip to content

Commit

Permalink
Refactor parsing string as enum
Browse files Browse the repository at this point in the history
  • Loading branch information
DrEsteban committed May 22, 2024
1 parent 264bd65 commit a1b90a9
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions obs-websocket-dotnet/Types/OutputStateChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a1b90a9

Please sign in to comment.