Inherits: ICloneable
Description
The AnyValue class provides a cross-language implementation of a dynamic object that can hold a value of any type. In addition, it provides methods to convert the stored value to different types, such as string or integer.
Constructors
Creates a new instance of the object and assigns its value.
publicAnyValue(object value = null)
- value: object - (optional) value used to initialize this object.
Creates a new instance of the object and assigns its value.
publicAnyValue(AnyValue value)
- value: object - (optional) value used to initialize this object.
Properties
Value
Value stored by this object.
publicobject Value [ get, private set ]
Instance methods
Clone
Creates a binary clone of this object.
publicobject Clone()
- returns: object - clone of this object.
Equals
Compares this object’s value to a specified value. When a direct comparison gives a negative results, it tries to compare values as strings.
public overridebool Equals(object obj)
- obj: object - value to be compared with.
- returns: bool - true when objects are equal and false otherwise.
EqualsAs
Compares this object’s value to a specified value.
When direct comparison gives negative results, it converts the
values to a type specified by a type code and compares them again.
T - the class type.
See TypeConverter.ToType
publicbool EqualsAs/(object obj)
- obj: object - args to be compared with.
- returns: object - true when the objects are equal and false otherwise.
GetAsArray
Converts an object’s value into an AnyArray or returns and empty AnyArray if the conversion is not possible.
See AnyValueArray.FromValue
publicAnyValueArray GetAsArray()
- returns: AnyValueArray - AnyArray value or an empty AnyArray if the conversion is not supported.
GetAsBoolean
Converts object value into a bool or returns false if the conversion is not possible.
publicbool GetAsBoolean()
- returns: bool - string value or false if the conversion is not supported.
GetAsBooleanWithDefault
Converts an object’s value into a bool or returns a given default value if the conversion is not possible.
See BooleanConverter.ToBooleanWithDefault
publicbool GetAsBooleanWithDefault(bool defaultValue)
- defaultValue: bool - default value.
- returns: bool - bool value or a given default if the conversion is not supported.
GetAsDateTime
Converts an object’s value into a DateTime or returns the current date if the conversion is not possible.
publicDateTime GetAsDateTime()
- returns: DateTime - DateTime value or the current date if the conversion is not supported.
GetAsDateTimeWithDefault
Converts an object’s value into a DateTime or returns a given default value if the conversion is not possible.
See DateTimeConverter.ToDateTimeWithDefault
publicDateTime GetAsDateTimeWithDefault(DateTime defaultValue)
- defaultValue: DateTime - default value.
- returns: DateTime - DateTime value or a given default if the conversion is not supported.
GetAsNullableTimeSpan
Converts an object’s value into TimeSpan or returns null if the conversion is not possible.
publicTimeSpan GetAsNullableTimeSpan()
- returns: TimeSpan - TimeSpan value or null if the conversion is not possible.
GetAsTimeSpan
Converts an object’s value into TimeSpan.
publicTimeSpan GetAsTimeSpan()
- returns: TimeSpan - TimeSpan value.
GetAsTimeSpanWithDefault
Converts an object’s value into TimeSpan or returns a given default if the conversion is not possible.
publicTimeSpan GetAsTimeSpanWithDefault(TimeSpan? defaultValue)
- defaultValue: TimeSpan - default value
- returns: TimeSpan - TimeSpan value or a given default if the conversion is not possible.
GetAsNullableEnum
Converts an object’s value into an Enum or returns null if the conversion is not possible.
publicT GetAsNullableEnum<T>()
- returns: T - Enum or null if the conversion is not possible
GetAsEnum
Converts an object’s value into an Enum.
publicT GetAsEnum<T>()
- returns: T - Enum
GetAsEnumWithDefault
Converts an object’s value into an Enum or returns a given default value is the conversion is not possible.
publicT GetAsEnumWithDefault<T>(T defaultValue)
- defaultValue: T - default value
- returns: T - Enum or given default value if the conversion is not possible.
GetAsDouble
Converts object value into a double or returns 0 if the conversion is not possible.
publicdouble GetAsDouble()
- returns: double - double value or 0 if the conversion is not supported.
GetAsDoubleWithDefault
Converts an object’s value into a double or returns a given default value if the conversion is not possible.
See DoubleConverter.ToDoubleWithDefault
publicdouble GetAsDoubleWithDefault(double defaultValue)
- defaultValue: double - default value.
- returns: double - double value or default if the conversion is not supported.
GetAsFloat
Converts an object’s value into a float or returns 0 if the conversion is not possible.
publicfloat GetAsFloat()
- returns: float - float value or 0 if the conversion is not supported.
GetAsFloatWithDefault
Converts an object’s value into a float or returns a given default value if the conversion is not possible.
See FloatConverter.ToFloatWithDefault
publicfloat GetAsFloatWithDefault(float defaultValue)
- defaultValue: float - default value.
- returns: float - float value or given default value if the conversion is not supported.
GetAsInteger
Converts an object’s value into an integer or returns 0 if the conversion is not possible.
publicint GetAsInteger()
- returns: GetAsInteger - integer value or 0 if the conversion is not supported.
GetAsIntegerWithDefault
Converts an object’s value into a integer or returns a given default value if the conversion is not possible.
See IntegerConverter.ToIntegerWithDefault
publicint GetAsIntegerWithDefault(int defaultValue)
- defaultValue: int - default value.
- returns: int - integer value or given default if the conversion is not supported.
GetAsLong
Converts an object’s value into a long or returns 0 if the conversion is not possible.
publiclong GetAsLong()
- returns: long - long value or 0 if the conversion is not supported.
GetAsLongWithDefault
Converts an object’s value into a long or returns a given default value if the conversion is not possible.
See LongConverter.ToLongWithDefault
publiclong GetAsLongWithDefault(long defaultValue)
- defaultValue: long - default value.
- returns: long - long value or given default if the conversion is not supported.
GetAsMap
Converts an object’s value into AnyMap or returns an empty AnyMap if the conversion is not possible.
See AnyValueMap.FromValue
publicAnyValueMap GetAsMap()
- returns: AnyValueMap - AnyMap value or empty AnyMap if the conversion is not supported.
GetAsNullableBoolean
Converts an object’s value into a bool or returns null if the conversion is not possible.
See BooleanConverter.ToNullableBoolean
publicbool GetAsNullableBoolean()
- returns: bool - bool value or null if the conversion is not supported.
GetAsNullableDateTime
Converts an object’s value into a DateTime or returns null if conversion is not possible.
See DateTimeConverter.ToNullableDateTime
publicDateTime sGetAsNullableDateTime()
- returns: DateTime - DateTime value or null if the conversion is not supported.
GetAsNullableDouble
Converts an object’s value into a double or returns null if the conversion is not possible.
See DoubleConverter.ToNullableDouble
publicdouble GetAsNullableDouble()
- returns: double - double value or null if the conversion is not supported.
GetAsNullableFloat
Converts an object’s value into a float or returns null if the conversion is not possible.
See FloatConverter.ToNullableFloat
publicfloat GetAsNullableFloat()
- returns: float - float value or null if the conversion is not supported.
GetAsNullableInteger
Converts an object’s value into an integer or returns null if the conversion is not possible.
See IntegerConverter.ToNullableInteger
publicint GetAsNullableInteger()
- returns: int - integer value or null if the conversion is not supported.
GetAsNullableLong
Converts an object’s value into a long or returns null if the conversion is not possible.
See LongConverter.ToNullableLong
publiclong GetAsNullableLong()
- returns: long - long value or null if the conversion is not supported.
GetAsNullableString
Converts an object’s value into a string or returns null if the conversion is not possible.
See StringConverter.ToNullableString
publicstring GetAsNullableString()
- returns: string - string value or null if the conversion is not supported.
GetAsNullableType
Converts an object’s value into a value defined by a specified typecode.
If the conversion is not possible, it returns null.
T - the class type
See TypeConverter.toNullableType
publicT GetAsNullableType<T>()
- returns: T - value defined by the typecode or null if the conversion is not supported.
GetAsObject
Gets the value stored in this object without any conversions.
publicobject GetAsObject()
- returns: object - object value.
GetAsString
Converts an object’s value into a string or returns "" if the conversion is not possible.
publicstring GetAsString()
- returns: string - string value or "" if the conversion is not supported.
GetAsStringWithDefault
Converts an object value into a string or returns a given default value if the conversion is not possible.
publicstring GetAsStringWithDefault(string defaultValue)
- defaultValue: string - default value.
- returns: string - string value or default if the conversion is not supported.
GetAsType
Converts an object’s value into a value defined by a specified typecode. If the conversion is not possible, it returns a given default value for the specified type. T - the class type.
publicT GetAsType<T>()
- returns: string - value defined by the typecode or given type default value if the conversion is not supported.
GetAsTypeWithDefault
Converts an object’s value into a value defined by a specified typecode. If the conversion is not possible, it returns the default value. T - the class type.
publicT GetAsTypeWithDefault<T>(T defaultValue)
- defaultValue: T - default value
- returns: T - value defined by the typecode or given type default value if the conversion is not supported.
GetTypeCode
Gets the type code for the value stored in this object.
See TypeConverter.ToTypeCode.
publicTypeCode GetTypeCode()
- returns: TypeCode - type code of the object’s value.
GetHashCode
Gets an object hash code which can be used to optimize storing and searching.
See TypeConverter.ToTypeCode.
public overrideint GetHashCode()
- returns: int - object hash code.
SetAsObject
Sets a new value for this object.
publicvoid SetAsObject(object value)
- value: object - new object value.
ToString
Gets a string representation of the object.
See StringConverter.ToString.
public overridestring ToString()
- returns: string - string representation of the object.
Examples
var value1 = new AnyValue("123.456");
value1.GetAsInteger(); // Result: 123
value1.GetAsString(); // Result: "123.456"
value1.GetAsFloat(); // Result: 123.456
See also
-
StringConverter
-
TypeConverter
-
BooleanConverter
-
IntegerConverter
-
LongConverter
-
DoubleConverter
-
FloatConverter
-
DateTimeConverter
-
ICloneable