AnyValueMap

Cross-language implementation of a dynamic map (dictionary) object that can hold values of any type. It also provides several methods to convert the stored values to different types.

Inherits: ICloneable, Dictionary<string, object>

Description

The AnyValueMap class provides a cross-language implementation of a dynamic map (dictionary) object that can hold values of any type. In addition, it provides several methods to convert the stored values to different types, such as bool, integer or datetime.

Constructors

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

public AnyValueMap(IDictionary<string, object> values)

  • values: any - (optional) values to initialize this map.

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

public AnyValueMap(IDictionary values)

  • values: any - (optional) values to initialize this map.

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

public AnyValueMap()

Instance methods

Append

Appends new elements to this map.

public void Append(IDictionary map)

  • map: IDictionary - a map with elements to be added.

Append

Appends new elements to this map.

public void Append(IDictionary<string, object> map)

  • map: IDictionary<string, object> - a map with elements to be added.

Clone

Creates a binary clone of this object.

public object Clone()

  • returns: object - a clone of this object.

Get

Gets a map element specified by its key.

public virtual object Get(string key)

  • key: string - a key of the element to get.
  • returns: object - the value of the map element.

GetAsArray

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

public AnyValueArray GetAsArray(string key)

  • key: string - a key of element to get.
  • returns: AnyValueArray - AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.

GetAsArrayWithDefault

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

public AnyValueArray GetAsArrayWithDefault(string key, AnyValueArray defaultValue)

  • key: string - a key of element to get.
  • defaultValue: AnyValueArray - the default value
  • returns: AnyValueArray - AnyValueArray value of the element or default value if conversion is not supported.

GetAsBoolean

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

public bool GetAsBoolean(string key)

  • key: string - a key of element to get.
  • returns: bool - value of the element or false if conversion is not supported.

GetAsBooleanWithDefault

Converts map element into a bool or returns default value if conversion is not possible.
See BooleanConverter.toBooleanWithDefault

public bool GetAsBooleanWithDefault(string key, bool defaultValue)

  • key: string - a key of element to get.
  • defaultValue: bool - the default value
  • returns: bool - bool value of the element or default value if conversion is not supported.

GetAsDateTime

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

public DateTime GetAsDateTime(string key)

  • key: string - a key of element to get.
  • returns: DateTime - DateTime value of the element or the current date if conversion is not supported.

GetAsDateTimeWithDefault

Converts map element into a DateTime or returns default value if conversion is not possible.
See DateTimeConverter.toDateTimeWithDefault

public DateTime GetAsDateTimeWithDefault(string key, DateTime defaultValue)

  • key: string - a key of element to get.
  • defaultValue: DateTime - the default value
  • returns: DateTime - DateTime value of the element or default value if conversion is not supported.

GetAsNullableTimeSpan

TODO: add description

public TimeSpan GetAsNullableTimeSpan(string key)

  • key: string - TODO: add description
  • returns: TimeSpan - TODO: add description

GetAsTimeSpan

TODO: add description

public TimeSpan GetAsTimeSpan(string key)

  • key: string - TODO: add description
  • returns: TimeSpan - TODO: add description

GetAsTimeSpanWithDefault

TODO: add description

public TimeSpan GetAsTimeSpanWithDefault(string key, TimeSpan? defaultValue)

  • key: string - TODO: add description
  • defaultValue: TimeSpan - TODO: add description
  • returns: TimeSpan - TODO: add description

GetAsNullableEnum

TODO: add description

public T GetAsNullableEnum<T>(string key)

  • key: string - TODO: add description
  • returns: T - TODO: add description

GetAsEnum

TODO: add description

public T GetAsEnum<T>(string key)

  • key: string - TODO: add description
  • returns: T - TODO: add description

GetAsEnumWithDefault

TODO: add description

public T GetAsEnumWithDefault<T>(string key, T defaultValue)

  • key: string - TODO: add description
  • defaultValue: T - TODO: add description
  • returns: T - TODO: add description

GetAsDouble

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

public double GetAsDouble(string key)

  • key: string - a key of element to get.
  • returns: double - double value of the element or 0 if conversion is not supported.

GetAsDoubleWithDefault

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

public double GetAsDoubleWithDefault(string key, double defaultValue)

  • key: string - a key of element to get.
  • defaultValue: double - the default value
  • returns: double - double value of the element or default value if conversion is not supported.

GetAsFloat

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

public float GetAsFloat(string key)

  • key: string - a key of element to get.
  • returns: float - float value of the element or 0 if conversion is not supported.

GetAsFloatWithDefault

Converts map element into a flot or returns default value if conversion is not possible.
See FloatConverter.ToFloatWithDefault

public float GetAsFloatWithDefault(string key, float defaultValue)

  • key: string - a key of element to get.
  • defaultValue: float - the default value
  • returns: float - flot value of the element or default value if conversion is not supported.

GetAsInteger

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

public int GetAsInteger(string key)

  • key: string - a key of element to get.
  • returns: int - integer value of the element or 0 if conversion is not supported.

GetAsIntegerWithDefault

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

public int GetAsIntegerWithDefault(string key, float defaultValue)

  • key: string - a key of element to get.
  • defaultValue: float - the default value
  • returns: float - integer value of the element or default value if conversion is not supported.

GetAsLong

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

public long GetAsLong(string key)

  • key: string - a key of element to get.
  • returns: long - long value of the element or 0 if conversion is not supported.

GetAsLongWithDefault

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

public long GetAsLongWithDefault(string key, long defaultValue)

  • key: string - a key of element to get.
  • defaultValue: long - the default value
  • returns: long - long value of the element or default value if conversion is not supported.

GetAsMap

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

public AnyValueMap GetAsMap(string key)

  • key: string - a key of element to get.
  • returns: AnyValueMap - AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.

GetAsMapWithDefault

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

public AnyValueMap GetAsMapWithDefault(string key, AnyValueMap defaultValue)

  • key: string - a key of element to get.
  • defaultValue: AnyValueMap - the default value
  • returns: AnyValueMap - AnyValueMap value of the element or default value if conversion is not supported.

GetAsNullableArray

Converts map element into an AnyValueArray or returns null if conversion is not possible.
See AnyValueMap, AnyValueMap.fromValue

public AnyValueMap GetAsNullableArray(string key)

  • key: string - a key of element to get.
  • returns: AnyValueMap - AnyValueArray value of the element or null if conversion is not supported.

GetAsNullableBoolean

Converts map element into a bool or returns null if conversion is not possible.
See BooleanConverter.toNullableBoolean

public bool GetAsNullableBoolean(string key)

  • key: string - a key of element to get.
  • returns: bool - bool value of the element or null if conversion is not supported.

GetAsNullableDateTime

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

public DateTime GetAsNullableDateTime(string key)

  • key: string - a key of element to get.
  • returns: DateTime - DateTime value of the element or null if conversion is not supported.

GetAsNullableDouble

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

public double GetAsNullableDouble(string key)

  • key: string - a key of element to get.
  • returns: double - double value of the element or null if conversion is not supported.

GetAsNullableFloat

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

public float GetAsNullableFloat(string key)

  • key: string - a key of element to get.
  • returns: float - float value of the element or null if conversion is not supported.

GetAsNullableInteger

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

public int GetAsNullableInteger(string key)

  • key: string - a key of element to get.
  • returns: int - integer value of the element or null if conversion is not supported.

GetAsNullableLong

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

public logn GetAsNullableLong(string key)

  • key: string - a key of element to get.
  • returns: logn - long value of the element or null if conversion is not supported.

GetAsNullableMap

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

public AnyValueMap GetAsNullableMap(string key)

  • key: string - a key of element to get.
  • returns: AnyValueMap - AnyValueMap value of the element or null if conversion is not supported.

GetAsNullableString

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

public string GetAsNullableString(string key)

  • key: string - a key of element to get.
  • returns: string - string value of the element or null if conversion is not supported.

GetAsNullableType

Converts map element into a value defined by specied typecode. If conversion is not possible it returns null.
See TypeConverter.toNullableType T - the class type

public T GetAsNullableType<T>(string key)

  • key: string - a key of element to get.
  • returns: T - element value defined by the typecode or null if conversion is not supported.

GetAsObject

Gets the value stored in this map element without any conversions

public object GetAsObject()

  • key: string - (optional) a key of the element to get
  • returns: object - the value of the map element.

GetAsObject

Gets the value stored in map element without any conversions. When element key is not defined it returns the entire map value.

public object GetAsObject(string key)

  • key: string - (optional) a key of the element to get
  • returns: object - the element value or value of the map when index is not defined.

GetAsString

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

public string GetAsString(string key)

  • key: string - a key of element to get.
  • returns: string - string value of the element or "" if conversion is not supported.

GetAsStringWithDefault

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

public string GetAsStringWithDefault(string key, string defaultValue)

  • key: string - a key of element to get.
  • defaultValue: string - the default value
  • returns: string - string value of the element or default value if conversion is not supported.

GetAsType

Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type. T - the class type

public T GetAsType<T>(string key)

  • key: string - a key of element to get.
  • returns: T - element value defined by the typecode or default if conversion is not supported.

GetAsTypeWithDefault

Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value.
T - the class type See TypeConverter.ToTypeWithDefault

public T GetAsTypeWithDefault<T>(string key, T defaultValue)

  • key: string - a key of element to get.
  • defaultValue: T - the default value
  • returns: T - element value defined by the typecode or default value if conversion is not supported.

GetAsValue

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

public AnyValue GetAsValue(string key)

  • key: string - a key of element to get.
  • returns: AnyValue -AnyValue value of the element or empty AnyValue if conversion is not supported.

Set

Puts a new value into map element specified by its key.

public virtual Set(string key, object value)

  • key: string - a key of the element to put.
  • value: object - a new value for map element.

SetAsObject

Sets a new value for this array element

public void SetAsObject(object value)

  • value: any - a new element or map value.

SetAsObject

Sets a new value to map element specified by its index. When the index is not defined, it resets the entire map value.

public void SetAsObject(string key, object value)

  • key: string - (optional) a key of the element to set
  • value: object - a new element or map value.

Static methods

FromMaps

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

public static AnyValueMap FromMaps(params IDictionary[] maps)

  • maps: IDictionary[] - an array of maps to be merged
  • returns: AnyValueMap - a newly created AnyValueMap.

FromTuples

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

public static AnyValueMap FromTuples(params object[] tuples)

  • tuples: object[] - a list of values where odd elements are keys and the following even elements are values
  • returns: AnyValueMap - a newly created AnyValueArray.

FromTuplesArray!

TODO: this method is not realized yet for this language

Creates a new AnyValueMap from a list of key-value pairs called tuples. The method is similar to fromTuples but tuples are passed as array instead of parameters.

public static AnyValueMap FromTuplesArray(params object[] tuples)

  • tuples: object[] - a list of values where odd elements are keys and the following even elements are values
  • returns: AnyValueMap - a newly created AnyValueArray.

FromValue

Converts specified value into AnyValueMap.

public static AnyValueMap FromValue(object value)

  • value: object - value to be converted
  • returns: AnyValueMap - a newly created AnyValueMap.

Examples

var value1 = new AnyValueMap(new Dictionary<string, object>{
    {"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 DateTime(2018,0,1)

See also