Table of Contents

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

baseOptionsLoader IOptionsLoader

The base IOptionsLoader.

configurationSection IConfigurationSection

The 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

baseOptionsLoader or configurationSection is null.

InvalidOperationException

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

Parameters

baseOptionsLoader IOptionsLoader

The base 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

baseOptionsLoader or selector is null.

InvalidOperationException

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

Parameters

baseOptionsLoader IOptionsLoader

The base IOptionsLoader.

key string

The 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

baseOptionsLoader or key is null.

InvalidOperationException

baseOptionsLoader 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 baseOptionsLoader, Expression<Func<TOptions, TMember>> memberSelector)

Parameters

baseOptionsLoader IOptionsLoader

The base 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

baseOptionsLoader or memberSelector is null.

InvalidOperationException

baseOptionsLoader 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 baseOptionsLoader, string key, IEnumerable<IInitializableOptions> children)

Parameters

baseOptionsLoader IOptionsLoader

The base IOptionsLoader.

key string

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

children IEnumerable<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

baseOptionsLoader is null.

ArgumentNullException

key is null.

ArgumentNullException

children is null.

InvalidOperationException

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

Parameters

baseOptionsLoader IOptionsLoader

The base IOptionsLoader.

key string

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

child IInitializableOptions

The 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

baseOptionsLoader is null.

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

Parameters

baseOptionsLoader IOptionsLoader

The base IOptionsLoader.

key string

The 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

baseOptionsLoader is null.

ArgumentNullException

key is null.