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
configuration
IConfigurationThe configuration instance to bind.
instance
objectThe 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
configuration
IConfigurationThe configuration instance to bind.
key
stringThe key of the configuration section to bind.
instance
objectThe 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
configuration
IConfigurationThe configuration instance to bind.
type
TypeThe 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
configuration
IConfigurationThe configuration.
type
TypeThe type to convert the value to.
key
stringThe 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
configuration
IConfigurationThe configuration.
type
TypeThe type to convert the value to.
key
stringThe key of the configuration section's value to convert.
defaultValue
objectThe 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
configuration
IConfigurationThe configuration.
key
stringThe key of the configuration section's value to convert.
Returns
- T
The converted value.
Type Parameters
T
The 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
configuration
IConfigurationThe configuration.
key
stringThe key of the configuration section's value to convert.
defaultValue
TThe default value to use if no value is found.
Returns
- T
The converted value.
Type Parameters
T
The 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
configuration
IConfigurationThe configuration instance to bind.
Returns
- T
The new instance of T if successful, default(T) otherwise.
Type Parameters
T
The type of the new instance to bind.