AnyValueArray

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

Inherits: ICloneable, List<object>

Description

The AnyValueArray class provides a cross-language implementation of a dynamic array object that can hold values of any type. In addition, it provides several methods to convert the stored values to different types, such as boolean, integer or datetime.

Constructors

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

public AnyValueArray(object[] values)

  • values: object[] - (optional) values used to initialize this array.

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

public AnyValueArray(IEnumerable values)

  • values: IEnumerable - (optional) values used to initialize this array.

Creates a new instance of the array.

public AnyValueArray()

Instance methods

Append

Appends new elements to this array.

public void Append(object[] values)

  • values: object[] - list of elements to be added.

Append

Appends new elements to this array.

public void Append(IEnumerable values)

  • values: IEnumerable - list of elements to be added.

Clone

Creates a binary clone of this object.

public object Clone()

  • returns: object - clone of this object.

Contains

Checks if this array contains a value. The check uses direct comparison between elements and the specified value.

public new bool Contains(object value)

  • value: object - value to be checked
  • returns: bool - true if this array contains the value or false otherwise.

ContainsAs

Checks if this array contains a value. The check before comparison converts the elements and the value to type specified by the type code.
See TypeConverter.ToType, TypeConverter.ToNullableType

public bool ContainsAs<T>(object value)

  • value: object - value to be checked
  • returns: bool - true if this array contains the value or false otherwise.

Get

Gets an array element specified by its index.

public virtual object Get(int index)

  • index: int - index of the element to get.
  • returns: object - value of the array element.

GetAsArray

Converts an array element to an AnyValueArray or returns an empty AnyValueArray if the conversion is not possible.

public AnyValueArray GetAsArray(int index)

  • index: int - index of the element to get.
  • returns: AnyValueArray - AnyValueArray value of the element or empty an AnyValueArray if the conversion is not supported.

GetAsArrayWithDefault

Converts an array element to an AnyValueArray or returns a given default value if the conversion is not possible.

public AnyValueArray GetAsArrayWithDefault(int index, AnyValueArray defaultValue)

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

GetAsBoolean

Converts an array element to a bool or returns false if the conversion is not possible.

public bool GetAsBoolean(int index)

  • index: int - index of the element to get.
  • returns: bool - bool value of the element or false if the conversion is not supported.

GetAsBooleanWithDefault

Converts an array element to a bool or returns a given default value if the conversion is not possible.
See BooleanConverter.ToBooleanWithDefault.

public bool GetAsBooleanWithDefault(int index, bool defaultValue)

  • index: int - index of the element to get.
  • defaultValue: bool - default value
  • returns: bool - bool value of the element or given default value if the conversion is not supported.

GetAsDateTime

Converts an array element to a DateTime or returns the current date if the conversion is not possible.

public DateTime GetAsDateTime(int index)

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

GetAsDateTimeWithDefault

Converts an array element to a DateTime or returns a given default value if the conversion is not possible.
See DateTimeConverter.ToDateTimeWithDefault.

public DateTime GetAsDateTimeWithDefault(int index, DateTime defaultValue?)

  • index: int - index of the element to get.
  • defaultValue: DateTime - default value
  • returns: DateTime - DateTime value ot the element or given default value if the conversion is not supported.

GetAsNullableTimeSpan

Converts an array element to TimeSpan or returns null if the conversion is not possible.

public TimeSpan GetAsNullableTimeSpan(int index)

  • index: int - index of the element to get.
  • returns: TimeSpan - TimeSpan or null if the conversion is not possible.

GetAsTimeSpan

Converts an array element into TimeSpan.

public TimeSpan GetAsTimeSpan(int index)

  • index: int - index of the element to get.
  • returns: TimeSpan - TimeSpan

GetAsTimeSpanWithDefault

Converts an array element to TimeSpan or returns a given default value if the conversion is not possible.

public TimeSpan GetAsTimeSpanWithDefault(int index, TimeSpan? defaultValue)

  • index: int - index of the element to get.
  • defaultValue: TimeSpan - given default value
  • returns: TimeSpan - TimeSpan or given default value if the conversion is not possible.

GetAsNullableEnum

Converts an array element to Enum or returns null if the conversion is not possible.

public T GetAsNullableEnum<T>(int index)

  • index: int - index of the element to get.
  • returns: T - Enum or null if the conversion is not possible.

GetAsEnum

Converts an array element to Enum.

public T GetAsEnum<T>(int index)

  • index: int - index of the element to get.
  • returns: T - Enum.

GetAsEnumWithDefault

Converts an array element to Enum or returns a givend default value if the conversion is not possible.

public T GetAsEnumWithDefault<T>(int index, T defaultValue)

  • index: int - index of the element to get.
  • defaultValue: T - default value
  • returns: T - Enum or a given default value if the conversion is not possile.

GetAsDouble

Converts an array element into a double or returns 0 if the conversion is not possible.

public double GetAsDouble(int index)

  • index: int - index of the element to get.
  • returns: double - double value ot the element or 0 if the conversion is not supported.

GetAsDoubleWithDefault

Converts array element into a double or returns a given default value if the conversion is not possible.

public double GetAsDoubleWithDefault(int index, double defaultValue)

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

GetAsFloat

Converts an array element into a float or returns 0 if the conversion is not possible.

public float GetAsFloat(int index)

  • index: int - index of the element to get.
  • returns: float - float value ot the element or 0 if the conversion is not supported.

GetAsFloatWithDefault

Converts an array element into a float or returns a given default value if the conversion is not possible.
See FloatConverter.ToFloatWithDefault

public float GetAsFloatWithDefault(int index, float defaultValue)

  • index: int - index of the element to get.
  • defaultValue: float - default value
  • returns: float - float value of the element or given default value if the conversion is not supported.

GetAsInteger

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

public int GetAsInteger(int index)

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

GetAsIntegerWithDefault

Converts array element into an integer or returns a given default value if the conversion is not possible.
See IntegerConverter.ToIntegerWithDefault

public int GetAsIntegerWithDefault(int index, int defaultValue)

  • index: int - index of the element to get.
  • defaultValue: int - default value
  • returns: int - integer value of the element or given default value if the conversion is not supported.

GetAsLong

Converts an array element into a long or returns 0 if the conversion is not possible.

public long getAsLong(int index)

  • index: int - index of the element to get.
  • returns: long - long value of the element or 0 if the conversion is not supported.

GetAsLongWithDefault

Converts an array element into a long or returns a given default value if the conversion is not possible.
See LongConverter.ToLongWithDefault

public long GetAsLongWithDefault(int index, long defaultValue)

  • index: int - index of the element to get.
  • defaultValue: long - default value
  • returns: long - long value of the element or given default value if the conversion is not supported.

GetAsMap

Converts an array element into an AnyValueMap or returns an empty AnyValueMap if the conversion is not possible.
See AnyValueMap, AnyValueMap.FromValue

public AnyValueMap GetAsMap(int index)

  • index: int - index of the element to get.
  • returns: AnyValueMap - AnyValueMap value of the element or an empty AnyValueMap if the conversion is not supported.

GetAsMapWithDefault

Converts an array element into an AnyValueMap or returns a give default value if the conversion is not possible.

public AnyValueMap GetAsMapWithDefault(int index, AnyValueMap defaultValue)

  • index: int - index of the element to get.
  • defaultValue: AnyValueMap - default value
  • returns: AnyValueMap - AnyValueMap value of the element or given default value if the conversion is not supported.

GetAsNullableArray

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

public AnyValueArray GetAsNullableArray(int index)

  • index: int - index of the element to get.
  • returns: AnyValueArray - AnyValueArray value of the element or null if the conversion is not supported.

GetAsNullableBoolean

Converts array element into a bool or returns null if the conversion is not possible.
See BooleanConverter.ToNullableBoolean

public bool GetAsNullableBoolean(int index)

  • index: int - index of element to get.
  • returns: bool - bool value of the element or null if the conversion is not supported.

GetAsNullableDateTime

Converts an array element into a DateTime or returns null if the conversion is not possible.
See DateTimeConverter.ToNullableDateTime

public DateTime GetAsNullableDateTime(int index)

  • index: int - index of element to get.
  • returns: DateTime - DateTime value of the element or null if the conversion is not supported.

GetAsNullableDouble

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

public double GetAsNullableDouble(int index)

  • index: int - index of the element to get.
  • returns: double - double value of the element or null if the conversion is not supported.

GetAsNullableFloat

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

public float GetAsNullableFloat(int index)

  • index: int - index of the element to get.
  • returns: float - float value of the element or null if the conversion is not supported.

GetAsNullableInteger

Converts an array element into a float or returns null if the conversion is not possible.
See IntegerConverter.ToNullableInteger

public float GetAsNullableInteger(int index)

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

GetAsNullableLong

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

public long GetAsNullableLong(int index)

  • index: int - index of the element to get.
  • returns: long - long value of the element or null if the conversion is not supported.

GetAsNullableMap

Converts an array element into a long or returns null if the conversion is not possible.
See AnyValueMap, AnyValueMap

public AnyValueMap GetAsNullableMap(int index)

  • index: int - index of the element to get.
  • returns: AnyValueMap - AnyValueMap value of the element or null if the conversion is not supported.

GetAsNullableString

Converts an array element into a string or returns null if the conversion is not possible.
See StringConverter.ToNullableString,

public string GetAsNullableString(int index)

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

GetAsNullableType

Converts an array element into a value defined by a specified typecode. If conversion is not possible, it returns null.
See TypeConverter.ToNullableType T - class type

public T GetAsNullableType<T>(int index)

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

GetAsNullableTypeWithDefault

Converts an array element into a value defined by specified typecode. If conversion is not possible, it returns a given default value. See TypeConverter.ToNullableType T - class type

public T GetAsNullableType<T>(int index, T defaultValue)

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

GetAsObject

Gets the value stored in this array element without any conversions.

public object GetAsObject()

  • returns: object - value of the array element.

GetAsObject

Gets the value stored in array element without any conversions. When element index is not defined, it returns the entire array value.

public object GetAsObject(int index)

  • index: int - (optional) index of the element to get
  • returns: object - element value or value of the array when the index is not defined.

GetAsString

Converts an array element into a string or returns "" if the conversion is not possible.

public string GetAsString(int index)

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

GetAsStringWithDefault

Converts an array element into a string or returns a given default value if the conversion is not possible.
See StringConverter.ToStringWithDefault

public string GetAsStringWithDefault(int index, string defaultValue)

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

GetAsType

Converts an array element into a value defined by a specified typecode. If the conversion is not possible, it returns the default value for the specified type.

public T GetAsType<T>(int index)

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

GetAsTypeWithDefault

Converts an array element into a value defined by specied typecode. If conversion is not possible, it returns a given default value for the specified type.
See TypeConverter.toTypeWithDefault

public T GetAsTypeWithDefault<T>(int index, T defaultValue)

  • index: int - index of the element to get.
  • defaultValue: T - default value
  • returns: T - element value defined by the typecode or given default value if the conversion is not supported.

GetAsValue

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

public AnyValue GetAsValue(int index)

  • index: int - index of the element to get.
  • returns: AnyValue - AnyValue value of the element or empty AnyValue if the conversion is not supported.

Set

Sets a new value into array element specified by its index.

public virtual void Set(int index, object value)

  • index: int - index of the element to put.
  • value: object - new value for array element.

SetAsObject

Sets a new value for this array element. See ArrayConverter.ToArray

public void SetAsObject(object value)

  • value: object - new element or array value.

SetAsObject

Sets a new value to an array element specified by its index. When the index is not defined, it resets the entire array value. See ArrayConverter.toArray

public void SetAsObject(int index, object value)

  • index: int - (optional) index of the element to set
  • value: object - new element or array value.

ToString

Gets a string representation of the object. The result is a comma-separated list of string representations of individual elements as “value1,value2,value3”
See StringConverter.ToString

public override string ToString()

  • returns: string - string representation of the object.

Static methods

FromString

Splits a specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.

public static AnyValueArray FromString(string values, char separator, bool removeDuplicates)

  • values: string - string value to be split and assigned to AnyValueArray
  • separator: char - separator to split the string
  • removeDuplicates: bool - (optional) true to remove duplicated elements
  • returns: AnyValueArray - newly created AnyValueArray.

FromString

Splits a specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.

public static AnyValueArray FromString(string values, char separator)

  • values: string - string value to be split and assigned to AnyValueArray
  • separator: char - separator to split the string
  • returns: AnyValueArray - newly created AnyValueArray.

FromValue

Splits a specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.
See ArrayConverter.ToNullableArray

public static AnyValueArray FromValue(object value)

  • values: object - value to be converted
  • returns: AnyValueArray - newly created AnyValueArray.

FromValues

Creates a new AnyValueArray from a list of values

public static AnyValueArray FromValues(params object[] values)

  • values: object[] - list of values to initialize the created AnyValueArray
  • returns: AnyValueArray - newly created AnyValueArray.

Examples

var value1 = new AnyValueArray(new object[]{1, "123.456", "2018-01-01"});

value1.GetAsBoolean(0);   // Result: true
value1.GetAsInteger(1);   // Result: 123
value1.GetAsFloat(1);     // Result: 123.456
value1.GetAsDateTime(2);  // Result: new DateTime(2018,0,1)

See also