Skip to content

Instantly share code, notes, and snippets.

@heemskerkerik
Created March 14, 2022 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heemskerkerik/e4bc9b86e096b1f0645041dedd069d5c to your computer and use it in GitHub Desktop.
Save heemskerkerik/e4bc9b86e096b1f0645041dedd069d5c to your computer and use it in GitHub Desktop.
static State ChangeState(State current, Transition transition, bool hasKey)
{
if (current == Opened && transition == Close)
return Closed;
else if (current == Closed && transition == Open)
return Open;
else if (current == Closed && transition == Lock && hasKey)
return Locked;
else if (current == Locked && transition == Unlock && hasKey)
return Closed;
else
throw new InvalidOperationException($"Invalid transition");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment