Created
October 22, 2019 12:19
-
-
Save mapfel/18ba181b47dacac9a672181eea560d6f to your computer and use it in GitHub Desktop.
Clean Code Samples
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
// Local functions offer some real benefits | |
// - improves readability from top till down and usage of method names for documentation purposes | |
// - supports the SLA principle to keep the abstraction level in a block or local funtion on the same level | |
// - avoid spreading "private scope" code in the file which pollutes the file structure | |
private static ProcessDetails GetProcessDetailsBy(BvmsApplication bvmsApplication) | |
{ | |
switch (bvmsApplication) | |
{ | |
case BvmsApplication.ConfigurationClient: | |
return GetConfigClientProcessDetails("ConfigClient"); | |
case BvmsApplication.OperationClient: | |
return GetConfigClientProcessDetails("OperatorClient"); | |
default: | |
throw new ArgumentOutOfRangeException(nameof(bvmsApplication), bvmsApplication, null); | |
} | |
ProcessDetails GetConfigClientProcessDetails(string app) | |
{ | |
var name = app; | |
var path = GetEnvironmentVariableOrDefault($"{app}.Path", appPath); | |
var arguments = GetEnvironmentVariableOrDefault($"{app}.Args", appArgs); | |
var directory = GetEnvironmentVariableOrDefault($"{app}.Directory", appDirectory); | |
return new ProcessDetails(name, path, arguments, directory); | |
} | |
string GetEnvironmentVariableOrDefault(string environmentVariable, string defaultValue) | |
{ | |
var result = Environment.GetEnvironmentVariable(environmentVariable); | |
return result.IsNotNullOrEmpty() ? result : defaultValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment