Skip to content

Instantly share code, notes, and snippets.

@devlead
Created September 28, 2019 23:42
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 devlead/51c7cc91c1430fba323c6a260c529042 to your computer and use it in GitHub Desktop.
Save devlead/51c7cc91c1430fba323c6a260c529042 to your computer and use it in GitHub Desktop.
// Switch expression
static string ToLevel(this Verbosity verbosity)
=> verbosity switch
{
Verbosity.Diagnostic => "[****]",
Verbosity.Verbose => "[*** ]",
Verbosity.Normal => "[** ]",
Verbosity.Minimal => "[* ]",
Verbosity.Quiet => "[ ]",
_ => throw new ArgumentOutOfRangeException(message: "invalid enum value",
actualValue: verbosity,
paramName: nameof(verbosity)),
};
Verbosity[] verbosities = null;
// Null-coalescing assignment
verbosities ??= (Verbosity[])Enum.GetValues(typeof(Verbosity));
// Range last 4
foreach(Verbosity verbosity in verbosities[^4..])
{
Information(
"{0} = {1:F}",
verbosity.ToLevel(),
verbosity
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment