Class IOptionsLoaderExtensions
- Namespace
- Acuit.Pinpoint.Workstation.Configuration
- Assembly
- Acuit.Pinpoint.Workstation.Interfaces.dll
Extension methods for IOptionsLoader.
public static class IOptionsLoaderExtensions
- Inheritance
-
IOptionsLoaderExtensions
- Inherited Members
Methods
CreateChildLoader(IOptionsLoader, IConfigurationSection)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader baseOptionsLoader, IConfigurationSection configurationSection)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
configurationSectionIConfigurationSectionThe child configuration section.
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
configurationSection can represent any configuration section within the same configuration as baseOptionsLoader, not just direct children.
Exceptions
- ArgumentNullException
baseOptionsLoaderorconfigurationSectionis null.- InvalidOperationException
baseOptionsLoaderhas no configuration section.
CreateChildLoader(IOptionsLoader, Func<IConfigurationSection, IConfigurationSection>)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader baseOptionsLoader, Func<IConfigurationSection, IConfigurationSection> selector)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
selectorFunc<IConfigurationSection, IConfigurationSection>A selector for the child IConfigurationSection. This takes one parameter, which is the IConfigurationSection of the base IOptionsLoader, and it should return the child IConfigurationSection.
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
selector can select any descendant member, not just direct children.
Exceptions
- ArgumentNullException
baseOptionsLoaderorselectoris null.- InvalidOperationException
baseOptionsLoaderhas no configuration section.
CreateChildLoader(IOptionsLoader, string)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader baseOptionsLoader, string key)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
keystringThe key of the child configuration section (relative to
baseOptionsLoader).
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
key can represent any descendant configuration section, not just direct children.
Exceptions
- ArgumentNullException
baseOptionsLoaderorkeyis null.- InvalidOperationException
baseOptionsLoaderhas no configuration section.
CreateChildLoader<TOptions, TMember>(IOptionsLoader, Expression<Func<TOptions, TMember>>)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader<TOptions, TMember>(this IOptionsLoader baseOptionsLoader, Expression<Func<TOptions, TMember>> memberSelector)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
memberSelectorExpression<Func<TOptions, TMember>>A lambda expression that selects a member of the options object.
Returns
- IOptionsLoader
The new IOptionsLoader.
Type Parameters
TOptionsThe strongly-typed options object type.
TMemberThe member type.
Remarks
memberSelector can select any descendant member, not just direct children.
See GetSectionFromSelector<TOptions, TMember>(IConfigurationSection, Expression<Func<TOptions, TMember>>) for more details about member selectors.
Exceptions
- ArgumentNullException
baseOptionsLoaderormemberSelectoris null.- InvalidOperationException
baseOptionsLoaderhas no configuration section.- InvalidOperationException
The
memberSelectorlambda expression does not select a member via simple member accesses and/or constant int indexers.
InitializeChildCollectionOptionsAsync(IOptionsLoader, string, IEnumerable<IInitializableOptions>)
Initializes options for a collection of child members that implement IInitializableOptions.
public static Task InitializeChildCollectionOptionsAsync(this IOptionsLoader baseOptionsLoader, string key, IEnumerable<IInitializableOptions> children)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
keystringThe key of the child collection configuration section (relative to
baseOptionsLoader).childrenIEnumerable<IInitializableOptions>The collection of children.
Returns
- Task
A task that represents the asynchronous operation.
Examples
public class ParentOptions : IInitializableOptions
{
public IList<ChildOptions> Children { get; } = new List<ChildOptions>();
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
await optionsLoader.InitializeChildCollectionOptionsAsync(nameof(Children), Children);
}
}
public class ChildOptions : IInitializableOptions
{
// TODO: Options members
public Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
// TODO: Initialize options
}
}
Exceptions
- ArgumentNullException
baseOptionsLoaderis null.- ArgumentNullException
keyis null.- ArgumentNullException
childrenis null.- InvalidOperationException
baseOptionsLoaderhas no configuration section.- InvalidOperationException
The number of children does not match the number of child configuration sections. This will be thrown after initializing all children for which there is a child configuration section.
InitializeChildOptionsAsync(IOptionsLoader, string, IInitializableOptions)
Initializes options for a child member that implements IInitializableOptions.
public static Task InitializeChildOptionsAsync(this IOptionsLoader baseOptionsLoader, string key, IInitializableOptions child)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
keystringThe key of the child configuration section (relative to
baseOptionsLoader).childIInitializableOptionsThe child member.
Returns
- Task
A task that represents the asynchronous operation.
Examples
public class ParentOptions : IInitializableOptions
{
public ChildOptions Child { get; } = new ChildOptions();
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
await optionsLoader.InitializeChildOptionsAsync(nameof(Child), Child);
}
}
public class ChildOptions : IInitializableOptions
{
// TODO: Options members
public Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
// TODO: Initialize options
}
}
Exceptions
- ArgumentNullException
baseOptionsLoaderis null.- ArgumentNullException
keyis null.- ArgumentNullException
childis null.
RetrieveChildFileAsync(IOptionsLoader, string)
Retrieves a file specified by a child option member.
public static Task<string> RetrieveChildFileAsync(this IOptionsLoader baseOptionsLoader, string key)
Parameters
baseOptionsLoaderIOptionsLoaderThe base IOptionsLoader.
keystringThe key of the child configuration setting (relative to
baseOptionsLoader) that specifies the file name.
Returns
- Task<string>
A task that represents the asynchronous operation. The value of its Result property contains the local path to the retrieved file, or null if the configuration setting file name value is null or empty, or if the file could not be retrieved.
Examples
public class MyOptions : IInitializableOptions
{
public string MyFileName { get; set; }
internal string MyLocalFileName { get; set; }
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
MyLocalFileName = await optionsLoader.RetrieveChildFileAsync(nameof(MyFileName));
}
}
Remarks
See the remarks for RetrieveFileAsync(string) for additional information (as this helper internally calls that method).
Exceptions
- ArgumentNullException
baseOptionsLoaderis null.- ArgumentNullException
keyis null.