Table of Contents

Class OptionsLoaderExtensions

Namespace
Acuit.Pinpoint.Workstation.Configuration
Assembly
Acuit.Pinpoint.Workstation.Abstractions.dll

Extension members for IOptionsLoader.

public static class OptionsLoaderExtensions
Inheritance
OptionsLoaderExtensions
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 optionsLoader, IConfigurationSection configurationSection)

Parameters

optionsLoader IOptionsLoader
configurationSection IConfigurationSection

The child configuration section.

Returns

IOptionsLoader

The new IOptionsLoader.

Remarks

configurationSection can represent any configuration section within the same configuration as optionsLoader, not just direct children.

Exceptions

ArgumentNullException

configurationSection is null.

InvalidOperationException

optionsLoader has 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 optionsLoader, Func<IConfigurationSection, IConfigurationSection> selector)

Parameters

optionsLoader IOptionsLoader
selector Func<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

selector is null.

InvalidOperationException

optionsLoader has 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 optionsLoader, string key)

Parameters

optionsLoader IOptionsLoader
key string

The key of the child configuration section (relative to optionsLoader).

Returns

IOptionsLoader

The new IOptionsLoader.

Remarks

key can represent any descendant configuration section, not just direct children.

Exceptions

ArgumentNullException

key is null.

InvalidOperationException

optionsLoader has 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 optionsLoader, Expression<Func<TOptions, TMember>> memberSelector) where TOptions : notnull where TMember : notnull

Parameters

optionsLoader IOptionsLoader
memberSelector Expression<Func<TOptions, TMember>>

A lambda expression that selects a member of the options object.

Returns

IOptionsLoader

The new IOptionsLoader.

Type Parameters

TOptions

The strongly-typed options object type.

TMember

The 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

memberSelector is null.

InvalidOperationException

optionsLoader has no configuration section.

InvalidOperationException

The memberSelector lambda 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 optionsLoader, string key, IEnumerable<IInitializableOptions> children)

Parameters

optionsLoader IOptionsLoader
key string

The key of the child collection configuration section (relative to optionsLoader).

children IEnumerable<IInitializableOptions>

The collection of children.

Returns

Task

The task object representing 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

key is null.

ArgumentNullException

children is null.

InvalidOperationException

optionsLoader has 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 optionsLoader, string key, IInitializableOptions child)

Parameters

optionsLoader IOptionsLoader
key string

The key of the child configuration section (relative to optionsLoader).

child IInitializableOptions

The child member.

Returns

Task

The task object representing 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

key is null.

ArgumentNullException

child is null.

RetrieveChildFileAsync(IOptionsLoader, string)

Retrieves a file specified by a child option member.

public static Task<string?> RetrieveChildFileAsync(this IOptionsLoader optionsLoader, string key)

Parameters

optionsLoader IOptionsLoader
key string

The key of the child configuration setting (relative to optionsLoader) that specifies the file name.

Returns

Task<string>

The task object representing the asynchronous operation.

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

Once the operation completes, the Result property on the returned task object 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.

See the remarks for RetrieveFileAsync(string) for additional information (as this helper internally calls that method).

Exceptions

ArgumentNullException

key is null.