Show / Hide Table of Contents

    Class ConfigurationAttribute

    An attribute that can be used to specify the default value to return if no value is defined in the configuration root.

    Inheritance
    System.Object
    System.Attribute
    ConfigurationAttribute
    Namespace: OpenCollar.Extensions.Configuration
    Assembly: OpenCollar.Extensions.Configuration.dll
    Syntax
    [AttributeUsage(AttributeTargets.Property)]
    public sealed class ConfigurationAttribute : Attribute
    Remarks

    Use the DefaultValue property of this attribute to manage the default value for configuration items that do not require and underlying setting.

    The Persistence property of this attribute can be used to control whether values are read or written to and from the underlying configuration source.

    The following UML has been generated directly from the source code using Jebbs PlantUML .

    Examples

    In the example below a property on an interface is defined with a default value, meaning that a value will be set, and no error will be thrown, even if there is no value in the underlying configuration service. In this case the result is a property that will be set to "DEFAULT" if no name is specified in configuration file.

    [Configuration(DefaultValue = "DEFAULT")]
    string Name
    {
    get; set;
    }

    In the following example the attribute is used to define the way in which a property is persisted. The value will be loaded from the configuration file, but never saved back to the file. This allows the application to change the value for all consumers of the interface, but it will never be changed in the file.

    [Configuration(Persistence = ConfigurationPersistenceActions.LoadOnly)]
    string InitialValue
    {
    get; set;
    }

    Constructors

    | Improve this Doc View Source

    ConfigurationAttribute()

    Initializes a new instance of the ConfigurationAttribute class.

    Declaration
    public ConfigurationAttribute()

    Properties

    | Improve this Doc View Source

    DefaultValue

    Gets the default value.

    Declaration
    public object DefaultValue { get; set; }
    Property Value
    Type Description
    System.Object

    The default value to return if no value is defined in the configuration root. Can be null.

    | Improve this Doc View Source

    Persistence

    Gets or sets the policy for when to load and save values from the configuration service.

    Declaration
    public ConfigurationPersistenceActions Persistence { get; set; }
    Property Value
    Type Description
    ConfigurationPersistenceActions

    The policy for when to load and save values from the configuration service.

    See Also

    System.Attribute
    ConfigurationPersistenceActions
    • Improve this Doc
    • View Source
    Back to top
    Copyright © 2019-2020 Jonathan Evans
    Version: 0.2.232