Class IConfigurationExtensions
- Namespace
- Songhay.Extensions
- Assembly
- SonghayCore.dll
Extensions of IConfiguration.
public static class IConfigurationExtensions
- Inheritance
-
IConfigurationExtensions
- Inherited Members
Methods
AddHelpDisplayText(IConfiguration?, string, string)
Adds conventional help text to IConfiguration under the specified key.
public static void AddHelpDisplayText(this IConfiguration? configuration, string key, string helpText)
Parameters
configurationIConfigurationthe IConfiguration
keystringthe key to add
helpTextstringthe help text to add
BindNewInstance<T>(IConfiguration)
Calls Bind(IConfiguration, string, object)
to return an instance of T
public static T BindNewInstance<T>(this IConfiguration configuration) where T : class, new()
Parameters
configurationIConfigurationthe IConfiguration
Returns
- T
Type Parameters
Tthe type of the desired instance
GetBasePathValue(IConfiguration?)
Returns the value of the conventional BaseDirectory arg
or throws DirectoryNotFoundException
when the conventional BaseDirectoryRequired arg is present.
public static string? GetBasePathValue(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
GetCommandLineArgValue(IConfiguration?, string)
Returns a value from the specified IConfiguration
by calling ToConfigurationKey(string?)
on the specified arg.
public static string? GetCommandLineArgValue(this IConfiguration? configuration, string arg)
Parameters
configurationIConfigurationthe IConfiguration
argstringthe command-line argument to be converted into a IConfiguration key
Returns
Remarks
This member will call ToConfigurationKey(string?) to convert a console argument to IConfiguration-key format.
GetOutputPath(IConfiguration?)
Returns the value of the conventional OutputFile arg
and will prefix it with the value of the BaseDirectory arg
when the conventional OutputUnderBasePath arg is present.
public static string? GetOutputPath(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
GetSettingsFilePath(IConfiguration?)
Returns the value of the conventional SettingsFile arg
which should be a path to a text file.
public static string GetSettingsFilePath(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
HasKey(IConfiguration?, string?)
Returns true when the specified IConfiguration
contains the specified key.
public static bool HasKey(this IConfiguration? configuration, string? key)
Parameters
configurationIConfigurationthe IConfiguration
keystringthe IConfiguration key
Returns
Remarks
This member will call ToConfigurationKey(string?) to convert a console argument to IConfiguration-key format.
HasKey(IConfiguration?, string?, bool)
Returns true when the specified IConfiguration
contains the specified key.
public static bool HasKey(this IConfiguration? configuration, string? key, bool isCommandLineSwitch)
Parameters
configurationIConfigurationthe IConfiguration
keystringthe IConfiguration key
isCommandLineSwitchboolwhen
true, expect a command-line “switch” like--dry-run=true
Returns
Remarks
This member will call ToConfigurationKey(string?) to convert a console argument to IConfiguration-key format.
When isCommandLineSwitch is true, a command-line “switch” like
--dry-run=false will make this member return false
and --dry-run=true will make this member return true.
For more detail, [ see https://github.com/BryanWilhite/SonghayCore/issues/177 ]
IsDryRun(IConfiguration?)
Determines whether args contain the conventional DryRun flag.
public static bool IsDryRun(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
IsHelpRequest(IConfiguration?)
Determines whether args contain the conventional Help flag.
public static bool IsHelpRequest(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
ReadSettings(IConfiguration?)
Reads the settings data in the file specified by SettingsFile which could be a relative or absolute path.
public static string ReadSettings(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
ReadStringInput(IConfiguration?)
Reads the input data in the inline string specified by InputString or the file specified by InputFile which could be a relative or absolute path.
public static string? ReadStringInput(this IConfiguration? configuration)
Parameters
configurationIConfiguration
Returns
Exceptions
ToHelpDisplayText(IConfiguration?)
Converts the specified IConfiguration to any keys ending with HelpTextSuffix.
public static string? ToHelpDisplayText(this IConfiguration? configuration)
Parameters
configurationIConfiguration
Returns
ToHelpDisplayText(IConfiguration?, int)
Converts the specified IConfiguration to any keys ending with HelpTextSuffix.
public static string? ToHelpDisplayText(this IConfiguration? configuration, int padding)
Parameters
configurationIConfigurationpaddingintthe padding between keys and values
Returns
ToKeys(IConfiguration?)
Converts the specified IConfiguration to a collection of its underlying keys.
public static IReadOnlyCollection<string> ToKeys(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
WithDefaultHelpText(IConfiguration?)
Returns IConfiguration with the conventional, console, args help text
for ConsoleArgsScalars.
public static IConfiguration? WithDefaultHelpText(this IConfiguration? configuration)
Parameters
configurationIConfigurationthe IConfiguration
Returns
WriteOutputToFile(IConfiguration?, byte[])
Writes the byte array output to the file specified by OutputFile.
public static void WriteOutputToFile(this IConfiguration? configuration, byte[] output)
Parameters
configurationIConfigurationthe IConfiguration
outputbyte[]the output to write
WriteOutputToFile(IConfiguration?, Stream)
Writes the Stream output to the file specified by OutputFile.
public static void WriteOutputToFile(this IConfiguration? configuration, Stream output)
Parameters
configurationIConfigurationthe IConfiguration
outputStreamthe output to write
Remarks
[ see https://stackoverflow.com/a/5515894/22944 ]
WriteOutputToFile(IConfiguration?, string)
Writes the string output to the file specified by OutputFile.
public static void WriteOutputToFile(this IConfiguration? configuration, string output)
Parameters
configurationIConfigurationthe IConfiguration
outputstringthe output to write
WriteOutputToFileAsync(IConfiguration?, byte[])
Writes the byte array output to the file specified by OutputFile.
public static Task WriteOutputToFileAsync(this IConfiguration? configuration, byte[] output)
Parameters
configurationIConfigurationthe IConfiguration
outputbyte[]the output to write
Returns
WriteOutputToFileAsync(IConfiguration?, Stream)
Writes the Stream output to the file specified by OutputFile.
public static Task WriteOutputToFileAsync(this IConfiguration? configuration, Stream output)
Parameters
configurationIConfigurationthe IConfiguration
outputStreamthe output to write
Returns
Remarks
[ see https://stackoverflow.com/a/5515894/22944 ]
WriteOutputToFileAsync(IConfiguration?, string)
Writes the string output to the file specified by OutputFile.
public static Task WriteOutputToFileAsync(this IConfiguration? configuration, string output)
Parameters
configurationIConfigurationthe IConfiguration
outputstringthe output to write