Pip-Services-Commons-Dotnet
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
PipServices3.Commons.Config.ConfigParams Class Reference

Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods. More...

Inheritance diagram for PipServices3.Commons.Config.ConfigParams:
PipServices3.Commons.Data.StringValueMap

Public Member Functions

 ConfigParams ()
 Creates an instance of ConfigParams. More...
 
 ConfigParams (IDictionary< string, string > content)
 Creates a new ConfigParams and fills it with values. More...
 
IEnumerable< string > GetSectionNames ()
 
ConfigParams GetSection (string section)
 Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys. More...
 
void AddSection (string section, ConfigParams sectionParams)
 Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix. More...
 
ConfigParams Override (ConfigParams configParams)
 Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object. More...
 
ConfigParams SetDefaults (ConfigParams defaultConfigParams)
 Set default values from specified ConfigParams and returns a new ConfigParams object. More...
 
- Public Member Functions inherited from PipServices3.Commons.Data.StringValueMap
 StringValueMap ()
 Creates a new instance of the map and assigns its value. More...
 
 StringValueMap (IDictionary< string, string > map)
 Creates a new instance of the map and assigns its value. More...
 
 StringValueMap (object value)
 Creates a new instance of the map and assigns its value. More...
 
virtual string Get (string key)
 Gets a map element specified by its key. More...
 
virtual void Set (string key, string value)
 Sets a new value for this array element by its key More...
 
void Append (IDictionary< string, object > map)
 Appends new elements to this map. More...
 
void Append (IDictionary< string, string > map)
 Appends new elements to this map. More...
 
object GetAsObject ()
 Gets the value stored in this map element without any conversions More...
 
void SetAsObject (object value)
 Sets a new value for this array element More...
 
void SetAsObject (string key, object value)
 Sets a new value to map element specified by its index. When the index is not defined, it resets the entire map value.This method has double purpose because method overrides are not supported in JavaScript. More...
 
object GetAsObject (string key)
 Gets the value stored in map element without any conversions. When element key is not defined it returns the entire map value. More...
 
string GetAsNullableString (string key)
 Converts map element into a string or returns null if conversion is not possible. More...
 
string GetAsString (string key)
 Converts map element into a string or returns "" if conversion is not possible. More...
 
string GetAsStringWithDefault (string key, string defaultValue)
 Converts map element into a string or returns default value if conversion is not possible. More...
 
bool GetAsNullableBoolean (string key)
 Converts map element into a boolean or returns null if conversion is not possible. More...
 
bool GetAsBoolean (string key)
 Converts map element into a boolean or returns false if conversion is not possible. More...
 
bool GetAsBooleanWithDefault (string key, bool defaultValue)
 Converts map element into a boolean or returns default value if conversion is not possible. More...
 
int GetAsNullableInteger (string key)
 Converts map element into an integer or returns null if conversion is not possible. More...
 
int GetAsInteger (string key)
 Converts map element into an integer or returns 0 if conversion is not possible. More...
 
int GetAsIntegerWithDefault (string key, int defaultValue)
 Converts map element into an integer or returns default value if conversion is not possible. More...
 
long GetAsNullableLong (string key)
 Converts map element into a long or returns null if conversion is not possible. More...
 
long GetAsLong (string key)
 Converts map element into a long or returns 0 if conversion is not possible. More...
 
long GetAsLongWithDefault (string key, long defaultValue)
 Converts map element into a long or returns default value if conversion is not possible. More...
 
float GetAsNullableFloat (string key)
 Converts map element into a float or returns null if conversion is not possible. More...
 
float GetAsFloat (string key)
 Converts map element into a float or returns 0 if conversion is not possible. More...
 
float GetAsFloatWithDefault (string key, float defaultValue)
 Converts map element into a float or returns default value if conversion is not possible. More...
 
double GetAsNullableDouble (string key)
 Converts map element into a double or returns null if conversion is not possible. More...
 
double GetAsDouble (string key)
 Converts map element into a double or returns 0 if conversion is not possible. More...
 
double GetAsDoubleWithDefault (string key, double defaultValue)
 Converts map element into a double or returns default value if conversion is not possible. More...
 
DateTime GetAsNullableDateTime (string key)
 Converts map element into a Date or returns null if conversion is not possible. More...
 
DateTime GetAsDateTime (string key)
 Converts map element into a Date or returns current date if conversion is not possible. More...
 
DateTime GetAsDateTimeWithDefault (string key, DateTime? defaultValue)
 Converts map element into a Date or returns default value if conversion is not possible. More...
 
TimeSpan GetAsNullableTimeSpan (string key)
 
TimeSpan GetAsTimeSpan (string key)
 
TimeSpan GetAsTimeSpanWithDefault (string key, TimeSpan? defaultValue)
 
GetAsNullableEnum< T > (string key)
 
GetAsEnum< T > (string key)
 
GetAsEnumWithDefault< T > (string key, T defaultValue)
 
GetAsNullableType< T > (string key)
 Converts map element into a value defined by specied typecode. If conversion is not possible it returns null. More...
 
GetAsType< T > (string key)
 Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value for the specied typecode. More...
 
GetAsTypeWithDefault< T > (string key, T defaultValue)
 Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value. More...
 
AnyValue GetAsValue (string key)
 Converts map element into an AnyValue or returns an empty AnyValue if conversion is not possible. More...
 
AnyValueArray GetAsNullableArray (string key)
 Converts map element into an AnyValueArray or returns null if conversion is not possible. More...
 
AnyValueArray GetAsArray (string key)
 Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible. More...
 
AnyValueArray GetAsArrayWithDefault (string key, AnyValueArray defaultValue)
 Converts map element into an AnyValueArray or returns default value if conversion is not possible. More...
 
AnyValueMap GetAsNullableMap (string key)
 Converts map element into an AnyValueMap or returns null if conversion is not possible. More...
 
AnyValueMap GetAsMap (string key)
 Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible. More...
 
AnyValueMap GetAsMapWithDefault (string key, AnyValueMap defaultValue)
 Converts map element into an AnyValueMap or returns default value if conversion is not possible. More...
 
override string ToString ()
 Gets a string representation of the object. The result is a semicolon-separated list of key-value pairs as "key1=value1;key2=value2;key=value3" More...
 
object Clone ()
 Creates a binary clone of this object. More...
 

Static Public Member Functions

static new ConfigParams FromValue (object value)
 Creates a new ConfigParams object filled with key-value pairs from specified object. More...
 
static new ConfigParams FromTuples (params object[] tuples)
 Creates a new ConfigParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs More...
 
static new ConfigParams FromString (string line)
 Creates a new ConfigParams object filled with key-value pairs serialized as a string. More...
 
static ConfigParams MergeConfigs (params IDictionary< string, string >[] configs)
 Merges two or more ConfigParams into one. The following ConfigParams override previously defined parameters. More...
 
- Static Public Member Functions inherited from PipServices3.Commons.Data.StringValueMap
static StringValueMap FromValue (object value)
 Converts specified value into StringValueMap. More...
 
static StringValueMap FromTuples (params object[] tuples)
 Creates a new StringValueMap from a list of key-value pairs called tuples. More...
 
static StringValueMap FromString (string line)
 arses semicolon-separated key-value pairs and returns them as a StringValueMap. More...
 
static StringValueMap FromMaps (params IDictionary< string, string >[] maps)
 Creates a new StringValueMap by merging two or more maps. Maps defined later in the list override values from previously defined maps. More...
 

Protected Member Functions

bool IsShadowName (string name)
 

Additional Inherited Members

- Properties inherited from PipServices3.Commons.Data.StringValueMap
new string this[string key] [get, set]
 

Detailed Description

Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods.

The keys are case-sensitive, so it is recommended to use consistent C-style as: "my_param"

Configuration parameters can be broken into sections and subsections using dot notation as: "section1.subsection1.param1". Using GetSection method all parameters from specified section can be extracted from a ConfigMap.

The ConfigParams supports serialization from/to plain strings as: "key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z" ConfigParams are used to pass configurations to IConfigurable objects. They also serve as a basis for more concrete configurations such as ConnectionParams or CredentialParams.

var config = ConfigParams.fromTuples( "section1.key1", "AAA",
"section1.key2", 123,
"section2.key1", true );
config.GetAsString("section1.key1"); // Result: AAA
config.GetAsInteger("section1.key1"); // Result: 0
var section1 = config.GetSection("section1");
section1.ToString(); // Result: key1=AAA;key2=123

See IConfigurable, StringValueMap

Constructor & Destructor Documentation

◆ ConfigParams() [1/2]

PipServices3.Commons.Config.ConfigParams.ConfigParams ( )

Creates an instance of ConfigParams.

◆ ConfigParams() [2/2]

PipServices3.Commons.Config.ConfigParams.ConfigParams ( IDictionary< string, string >  content)

Creates a new ConfigParams and fills it with values.

Parameters
content(optional) an object to be converted into key-value pairs to initialize this config map.

See StringValueMap

Member Function Documentation

◆ AddSection()

void PipServices3.Commons.Config.ConfigParams.AddSection ( string  section,
ConfigParams  sectionParams 
)

Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix.

Parameters
sectionname of the section where add new parameters
sectionParamsnew parameters to be added.

◆ FromString()

static new ConfigParams PipServices3.Commons.Config.ConfigParams.FromString ( string  line)
static

Creates a new ConfigParams object filled with key-value pairs serialized as a string.

Parameters
linea string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
Returns
a new ConfigParams object.

See StringValueMap.FromString(string)

◆ FromTuples()

static new ConfigParams PipServices3.Commons.Config.ConfigParams.FromTuples ( params object []  tuples)
static

Creates a new ConfigParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs

Parameters
tuplesthe tuples to fill a new ConfigParams object.
Returns
a new ConfigParams object.

See StringValueMap.FromTuples(object[])

◆ FromValue()

static new ConfigParams PipServices3.Commons.Config.ConfigParams.FromValue ( object  value)
static

Creates a new ConfigParams object filled with key-value pairs from specified object.

Parameters
valuean object with key-value pairs used to initialize a new ConfigParams.
Returns
a new ConfigParams object.

See RecursiveObjectReader.GetProperties(object)

◆ GetSection()

ConfigParams PipServices3.Commons.Config.ConfigParams.GetSection ( string  section)

Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys.

Parameters
sectionname of the section to retrieve configuration parameters from.
Returns
all configuration parameters that belong to the section named 'section'.

◆ MergeConfigs()

static ConfigParams PipServices3.Commons.Config.ConfigParams.MergeConfigs ( params IDictionary< string, string > []  configs)
static

Merges two or more ConfigParams into one. The following ConfigParams override previously defined parameters.

Parameters
configsa list of ConfigParams objects to be merged.
Returns
a new ConfigParams object.

See StringValueMap.FromMaps(IDictionary<string, string>[])

◆ Override()

ConfigParams PipServices3.Commons.Config.ConfigParams.Override ( ConfigParams  configParams)

Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object.

Parameters
configParamsConfigMap with parameters to override the current values.
Returns
a new ConfigParams object.

See ConfigParams.SetDefaults(ConfigParams)

◆ SetDefaults()

ConfigParams PipServices3.Commons.Config.ConfigParams.SetDefaults ( ConfigParams  defaultConfigParams)

Set default values from specified ConfigParams and returns a new ConfigParams object.

Parameters
defaultConfigParamsConfigMap with default parameter values.
Returns
a new ConfigParams object.

See ConfigParams.Override(ConfigParams)


The documentation for this class was generated from the following file: