Created
September 28, 2019 23:42
-
-
Save devlead/51c7cc91c1430fba323c6a260c529042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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