Class ConfigurationBinder
- Namespace
- Acuit.Pinpoint.Configuration
- Assembly
- Acuit.Pinpoint.Configuration.dll
Static helper class that allows binding strongly typed objects to configuration values.
public static class ConfigurationBinder
- Inheritance
-
ConfigurationBinder
- Inherited Members
Methods
Bind(IConfiguration, object)
Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.
public static void Bind(this IConfiguration configuration, object instance)
Parameters
configurationIConfigurationThe configuration instance to bind.
instanceobjectThe object to bind.
Bind(IConfiguration, string, object)
Attempts to bind the given object instance to the configuration section specified by the key by matching property names against configuration keys recursively.
public static void Bind(this IConfiguration configuration, string key, object instance)
Parameters
configurationIConfigurationThe configuration instance to bind.
keystringThe key of the configuration section to bind.
instanceobjectThe object to bind.
Get(IConfiguration, Type)
Attempts to bind the configuration instance to a new instance of type T. If this configuration section has a value, that will be used. Otherwise binding by matching property names against configuration keys recursively.
public static object Get(this IConfiguration configuration, Type type)
Parameters
configurationIConfigurationThe configuration instance to bind.
typeTypeThe type of the new instance to bind.
Returns
- object
The new instance if successful, null otherwise.
GetValue(IConfiguration, Type, string)
Extracts the value with the specified key and converts it to the specified type.
public static object GetValue(this IConfiguration configuration, Type type, string key)
Parameters
configurationIConfigurationThe configuration.
typeTypeThe type to convert the value to.
keystringThe key of the configuration section's value to convert.
Returns
- object
The converted value.
GetValue(IConfiguration, Type, string, object)
Extracts the value with the specified key and converts it to the specified type.
public static object GetValue(this IConfiguration configuration, Type type, string key, object defaultValue)
Parameters
configurationIConfigurationThe configuration.
typeTypeThe type to convert the value to.
keystringThe key of the configuration section's value to convert.
defaultValueobjectThe default value to use if no value is found.
Returns
- object
The converted value.
GetValue<T>(IConfiguration, string)
Extracts the value with the specified key and converts it to type T.
public static T GetValue<T>(this IConfiguration configuration, string key)
Parameters
configurationIConfigurationThe configuration.
keystringThe key of the configuration section's value to convert.
Returns
- T
The converted value.
Type Parameters
TThe type to convert the value to.
GetValue<T>(IConfiguration, string, T)
Extracts the value with the specified key and converts it to type T.
public static T GetValue<T>(this IConfiguration configuration, string key, T defaultValue)
Parameters
configurationIConfigurationThe configuration.
keystringThe key of the configuration section's value to convert.
defaultValueTThe default value to use if no value is found.
Returns
- T
The converted value.
Type Parameters
TThe type to convert the value to.
Get<T>(IConfiguration)
Attempts to bind the configuration instance to a new instance of type T. If this configuration section has a value, that will be used. Otherwise binding by matching property names against configuration keys recursively.
public static T Get<T>(this IConfiguration configuration)
Parameters
configurationIConfigurationThe configuration instance to bind.
Returns
- T
The new instance of T if successful, default(T) otherwise.
Type Parameters
TThe type of the new instance to bind.