Pip-Services-Commons-Dotnet
Public Member Functions | Static Public Member Functions | Properties | List of all members
PipServices3.Commons.Data.StringValueMap Class Reference

Cross-language implementation of a map (dictionary) where all keys and values are strings. The stored values can be converted to different types using variety of accessor methods. More...

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

Public Member Functions

 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 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...
 

Properties

new string this[string key] [get, set]
 

Detailed Description

Cross-language implementation of a map (dictionary) where all keys and values are strings. The stored values can be converted to different types using variety of accessor methods.

The string map is highly versatile.It can be converted into many formats, stored and sent over the wire.

This class is widely used in Pip.Services as a basis for variety of classes, such as ConfigParams, ConnectionParams, CredentialParams and others.

var value1 = StringValueMap.FromString("key1=1;key2=123.456;key3=2018-01-01");
value1.GetAsBoolean("key1"); // Result: true
value1.GetAsInteger("key2"); // Result: 123
value1.GetAsFloat("key2"); // Result: 123.456
value1.GetAsDateTime("key3"); // Result: new Date(2018,0,1)

See StringConverter, BooleanConverter, IntegerConverter, LongConverter, DoubleConverter, FloatConverter, DateTimeConverter, ICloneable

Constructor & Destructor Documentation

◆ StringValueMap() [1/3]

PipServices3.Commons.Data.StringValueMap.StringValueMap ( )

Creates a new instance of the map and assigns its value.

◆ StringValueMap() [2/3]

PipServices3.Commons.Data.StringValueMap.StringValueMap ( IDictionary< string, string >  map)

Creates a new instance of the map and assigns its value.

Parameters
map(optional) values to initialize this map.

◆ StringValueMap() [3/3]

PipServices3.Commons.Data.StringValueMap.StringValueMap ( object  value)

Creates a new instance of the map and assigns its value.

Parameters
value(optional) values to initialize this map.

Member Function Documentation

◆ Append() [1/2]

void PipServices3.Commons.Data.StringValueMap.Append ( IDictionary< string, object >  map)

Appends new elements to this map.

Parameters
mapa map with elements to be added.

◆ Append() [2/2]

void PipServices3.Commons.Data.StringValueMap.Append ( IDictionary< string, string >  map)

Appends new elements to this map.

Parameters
mapa map with elements to be added.

◆ Clone()

object PipServices3.Commons.Data.StringValueMap.Clone ( )

Creates a binary clone of this object.

Returns
a clone of this object.

◆ FromMaps()

static StringValueMap PipServices3.Commons.Data.StringValueMap.FromMaps ( params IDictionary< string, string > []  maps)
static

Creates a new StringValueMap by merging two or more maps. Maps defined later in the list override values from previously defined maps.

Parameters
mapsan array of maps to be merged
Returns
a newly created StringValueMap.

◆ FromString()

static StringValueMap PipServices3.Commons.Data.StringValueMap.FromString ( string  line)
static

arses semicolon-separated key-value pairs and returns them as a StringValueMap.

Parameters
linesemicolon-separated key-value list to initialize StringValueMap.
Returns
a newly created StringValueMap.

◆ FromTuples()

static StringValueMap PipServices3.Commons.Data.StringValueMap.FromTuples ( params object []  tuples)
static

Creates a new StringValueMap from a list of key-value pairs called tuples.

Parameters
tuplesa list of values where odd elements are keys and the following even elements are values
Returns
a newly created StringValueArray.

◆ FromValue()

static StringValueMap PipServices3.Commons.Data.StringValueMap.FromValue ( object  value)
static

Converts specified value into StringValueMap.

Parameters
valuevalue to be converted
Returns
a newly created StringValueMap.

◆ Get()

virtual string PipServices3.Commons.Data.StringValueMap.Get ( string  key)
virtual

Gets a map element specified by its key.

Parameters
keya key of the element to get.
Returns
the value of the map element.

◆ GetAsArray()

AnyValueArray PipServices3.Commons.Data.StringValueMap.GetAsArray ( string  key)

Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.

Parameters
keya key of element to get.
Returns
AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.

See AnyValueArray.FromValue(object)

◆ GetAsArrayWithDefault()

AnyValueArray PipServices3.Commons.Data.StringValueMap.GetAsArrayWithDefault ( string  key,
AnyValueArray  defaultValue 
)

Converts map element into an AnyValueArray or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
AnyValueArray value of the element or default value if conversion is not supported.

See GetAsNullableArray(string)

◆ GetAsBoolean()

bool PipServices3.Commons.Data.StringValueMap.GetAsBoolean ( string  key)

Converts map element into a boolean or returns false if conversion is not possible.

Parameters
keya key of element to get.
Returns
boolean value of the element or false if conversion is not supported.

See GetAsBooleanWithDefault(string, bool)

◆ GetAsBooleanWithDefault()

bool PipServices3.Commons.Data.StringValueMap.GetAsBooleanWithDefault ( string  key,
bool  defaultValue 
)

Converts map element into a boolean or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
boolean value of the element or default value if conversion is not supported.

See BooleanConverter.ToBooleanWithDefault(object, bool)

◆ GetAsDateTime()

DateTime PipServices3.Commons.Data.StringValueMap.GetAsDateTime ( string  key)

Converts map element into a Date or returns current date if conversion is not possible.

Parameters
keya key of element to get.
Returns
DateTime value of the element or current date if conversion is not supported.

See GetAsDateTimeWithDefault(string, DateTime?)

◆ GetAsDateTimeWithDefault()

DateTime PipServices3.Commons.Data.StringValueMap.GetAsDateTimeWithDefault ( string  key,
DateTime?  defaultValue 
)

Converts map element into a Date or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
DateTime value of the element or default value if conversion is not supported.

See DateTimeConverter.ToDateTimeWithDefault(object, DateTime?)

◆ GetAsDouble()

double PipServices3.Commons.Data.StringValueMap.GetAsDouble ( string  key)

Converts map element into a double or returns 0 if conversion is not possible.

Parameters
keya key of element to get.
Returns
double value of the element or 0 if conversion is not supported.

See GetAsDoubleWithDefault(string, double)

◆ GetAsDoubleWithDefault()

double PipServices3.Commons.Data.StringValueMap.GetAsDoubleWithDefault ( string  key,
double  defaultValue 
)

Converts map element into a double or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
double value of the element or default value if conversion is not supported.

See DoubleConverter.ToDoubleWithDefault(object, double)

◆ GetAsFloat()

float PipServices3.Commons.Data.StringValueMap.GetAsFloat ( string  key)

Converts map element into a float or returns 0 if conversion is not possible.

Parameters
keya key of element to get.
Returns
float value of the element or 0 if conversion is not supported.

See GetAsFloatWithDefault(string, float)

◆ GetAsFloatWithDefault()

float PipServices3.Commons.Data.StringValueMap.GetAsFloatWithDefault ( string  key,
float  defaultValue 
)

Converts map element into a float or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
float value of the element or default value if conversion is not supported.

See FloatConverter.ToFloatWithDefault(object, float)

◆ GetAsInteger()

int PipServices3.Commons.Data.StringValueMap.GetAsInteger ( string  key)

Converts map element into an integer or returns 0 if conversion is not possible.

Parameters
keya key of element to get.
Returns
integer value of the element or 0 if conversion is not supported.

See GetAsIntegerWithDefault(string, int)

◆ GetAsIntegerWithDefault()

int PipServices3.Commons.Data.StringValueMap.GetAsIntegerWithDefault ( string  key,
int  defaultValue 
)

Converts map element into an integer or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
integer value of the element or default value if conversion is not supported.

See IntegerConverter.ToIntegerWithDefault(object, int)

◆ GetAsLong()

long PipServices3.Commons.Data.StringValueMap.GetAsLong ( string  key)

Converts map element into a long or returns 0 if conversion is not possible.

Parameters
keya key of element to get.
Returns
long value of the element or 0 if conversion is not supported.

See GetAsLongWithDefault(string, long)

◆ GetAsLongWithDefault()

long PipServices3.Commons.Data.StringValueMap.GetAsLongWithDefault ( string  key,
long  defaultValue 
)

Converts map element into a long or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
long value of the element or default value if conversion is not supported.

See LongConverter.ToLongWithDefault(object, long)

◆ GetAsMap()

AnyValueMap PipServices3.Commons.Data.StringValueMap.GetAsMap ( string  key)

Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.

Parameters
keya key of element to get.
Returns
AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.

See FromValue(object)

◆ GetAsMapWithDefault()

AnyValueMap PipServices3.Commons.Data.StringValueMap.GetAsMapWithDefault ( string  key,
AnyValueMap  defaultValue 
)

Converts map element into an AnyValueMap or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
AnyValueMap value of the element or default value if conversion is not supported.

See GetAsNullableMap(string)

◆ GetAsNullableArray()

AnyValueArray PipServices3.Commons.Data.StringValueMap.GetAsNullableArray ( string  key)

Converts map element into an AnyValueArray or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
AnyValueArray value of the element or null if conversion is not supported.

See AnyValueArray

◆ GetAsNullableBoolean()

bool PipServices3.Commons.Data.StringValueMap.GetAsNullableBoolean ( string  key)

Converts map element into a boolean or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
boolean value of the element or null if conversion is not supported.

See BooleanConverter.ToNullableBoolean(object)

◆ GetAsNullableDateTime()

DateTime PipServices3.Commons.Data.StringValueMap.GetAsNullableDateTime ( string  key)

Converts map element into a Date or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
DateTime value of the element or null if conversion is not supported.

See DateTimeConverter.ToNullableDateTime(object)

◆ GetAsNullableDouble()

double PipServices3.Commons.Data.StringValueMap.GetAsNullableDouble ( string  key)

Converts map element into a double or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
double value of the element or null if conversion is not supported.

See DoubleConverter.ToNullableDouble(object)

◆ GetAsNullableFloat()

float PipServices3.Commons.Data.StringValueMap.GetAsNullableFloat ( string  key)

Converts map element into a float or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
float value of the element or null if conversion is not supported.

See FloatConverter.ToNullableFloat(object)

◆ GetAsNullableInteger()

int PipServices3.Commons.Data.StringValueMap.GetAsNullableInteger ( string  key)

Converts map element into an integer or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
integer value of the element or null if conversion is not supported.

See IntegerConverter.ToNullableInteger(object)

◆ GetAsNullableLong()

long PipServices3.Commons.Data.StringValueMap.GetAsNullableLong ( string  key)

Converts map element into a long or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
long value of the element or null if conversion is not supported.

See LongConverter.ToNullableLong(object)

◆ GetAsNullableMap()

AnyValueMap PipServices3.Commons.Data.StringValueMap.GetAsNullableMap ( string  key)

Converts map element into an AnyValueMap or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
AnyValueMap value of the element or null if conversion is not supported.

See FromValue(object)

◆ GetAsNullableString()

string PipServices3.Commons.Data.StringValueMap.GetAsNullableString ( string  key)

Converts map element into a string or returns null if conversion is not possible.

Parameters
keya key of element to get.
Returns
string value of the element or null if conversion is not supported.

See StringConverter.ToNullableString(object)

◆ GetAsNullableType< T >()

T PipServices3.Commons.Data.StringValueMap.GetAsNullableType< T > ( string  key)

Converts map element into a value defined by specied typecode. If conversion is not possible it returns null.

Template Parameters
Tthe class type
Parameters
keya key of element to get.
Returns
element value defined by the typecode or null if conversion is not supported.

See TypeConverter.ToNullableType<T>(object)

Type Constraints
T :struct 

◆ GetAsObject() [1/2]

object PipServices3.Commons.Data.StringValueMap.GetAsObject ( )

Gets the value stored in this map element without any conversions

Returns
the value of the map element.

◆ GetAsObject() [2/2]

object PipServices3.Commons.Data.StringValueMap.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.

Parameters
key(optional) a key of the element to get
Returns
the element value or value of the map when index is not defined.

◆ GetAsString()

string PipServices3.Commons.Data.StringValueMap.GetAsString ( string  key)

Converts map element into a string or returns "" if conversion is not possible.

Parameters
keya key of element to get.
Returns
string value of the element or "" if conversion is not supported.

See GetAsStringWithDefault(string, string)

◆ GetAsStringWithDefault()

string PipServices3.Commons.Data.StringValueMap.GetAsStringWithDefault ( string  key,
string  defaultValue 
)

Converts map element into a string or returns default value if conversion is not possible.

Parameters
keya key of element to get.
defaultValuethe default value
Returns
string value of the element or default value if conversion is not supported.

See StringConverter.ToStringWithDefault(object, string)

◆ GetAsType< T >()

T PipServices3.Commons.Data.StringValueMap.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.

Template Parameters
Tthe class type
Parameters
keya key of element to get.
Returns
element value defined by the typecode or default value if conversion is not supported.

See TypeConverter.ToType<T>(object)

Type Constraints
T :struct 

◆ GetAsTypeWithDefault< T >()

T PipServices3.Commons.Data.StringValueMap.GetAsTypeWithDefault< T > ( string  key,
defaultValue 
)

Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value.

Template Parameters
Tthe class type
Parameters
keya key of element to get.
defaultValuethe default value
Returns
element value defined by the typecode or default value if conversion is not supported.

See TypeConverter.ToTypeWithDefault<T>(object, T)

Type Constraints
T :struct 

◆ GetAsValue()

AnyValue PipServices3.Commons.Data.StringValueMap.GetAsValue ( string  key)

Converts map element into an AnyValue or returns an empty AnyValue if conversion is not possible.

Parameters
keya key of element to get.
Returns
AnyValue value of the element or empty AnyValue if conversion is not supported.

See AnyValue

◆ Set()

virtual void PipServices3.Commons.Data.StringValueMap.Set ( string  key,
string  value 
)
virtual

Sets a new value for this array element by its key

Parameters
keya key of the element to set.
valuethe new object value.

◆ SetAsObject() [1/2]

void PipServices3.Commons.Data.StringValueMap.SetAsObject ( object  value)

Sets a new value for this array element

Parameters
valuethe new object value.

◆ SetAsObject() [2/2]

void PipServices3.Commons.Data.StringValueMap.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.

Parameters
key(optional) a key of the element to set
valuea new element or map value.

◆ ToString()

override string PipServices3.Commons.Data.StringValueMap.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"

Returns
a string representation of the object.

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