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.
publicAnyValueArray(object[] values)
- values: object[] - (optional) values used to initialize this array.
Creates a new instance of the array and assigns its value.
publicAnyValueArray(IEnumerable values)
- values: IEnumerable - (optional) values used to initialize this array.
Creates a new instance of the array.
publicAnyValueArray()
Instance methods
Append
Appends new elements to this array.
publicvoid Append(object[] values)
- values: object[] - list of elements to be added.
Append
Appends new elements to this array.
publicvoid Append(IEnumerable values)
- values: IEnumerable - list of elements to be added.
Clone
Creates a binary clone of this object.
publicobject 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 newbool 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
publicbool 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 virtualobject 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.
publicAnyValueArray 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.
publicAnyValueArray 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.
publicbool 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.
publicbool 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.
publicDateTime 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.
publicDateTime 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.
publicTimeSpan 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.
publicTimeSpan 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.
publicTimeSpan 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.
publicT 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.
publicT 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.
publicT 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.
publicdouble 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.
publicdouble 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.
publicfloat 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
publicfloat 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.
publicint 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
publicint 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.
publiclong 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
publiclong 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
publicAnyValueMap 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.
publicAnyValueMap 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.
publicAnyValueArray 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
publicbool 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
publicDateTime 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
publicdouble 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
publicfloat 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
publicfloat 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
publiclong 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
publicAnyValueMap 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,
publicstring 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
publicT 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
publicT 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.
publicobject 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.
publicobject 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.
publicstring 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
publicstring 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.
publicT 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
publicT 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
publicAnyValue 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 virtualvoid 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
publicvoid 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
publicvoid 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 overridestring 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 staticAnyValueArray 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 staticAnyValueArray 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 staticAnyValueArray 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 staticAnyValueArray 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
-
StringConverter
-
TypeConverter
-
StringConverter
-
BooleanConverter
-
IntegerConverter
-
LongConverter
-
DoubleConverter
-
FloatConverter
-
DateTimeConverter
-
ICloneable