Class SimpleValue
A simple implementation of the IXmlValue interface.
Inherited Members
Namespace: Tangosol.Run.Xml
Assembly: Coherence.dll
Syntax
public class SimpleValue : IXmlValue, ICloneable, IPortableObject
Remarks
Protected methods are provided to support inheriting classes.
Constructors
SimpleValue()
Construct an empty SimpleValue.
Declaration
public SimpleValue()
SimpleValue(object)
Construct a SimpleValue.
Declaration
public SimpleValue(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The initial value for this SimpleValue. |
Remarks
Constructs an element's content value from the passed object value. If the object is a string, then the string should be un-escaped by this point; it must not still be in the form of the CDATA construct.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If the string value is illegal. |
SimpleValue(object, bool)
Construct a SimpleValue.
Declaration
public SimpleValue(object value, bool isAttribute)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The initial value for this SimpleValue. |
| bool | isAttribute | true if this SimpleValue is an element attribute value; false if an element's content's value. |
Remarks
Constructs an element's content or attribute value from the passed string value. The string should be un-escaped by this point; it must not still be in the form of the CDATA construct.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If the string value is illegal. |
SimpleValue(object, bool, bool)
Construct a SimpleValue.
Declaration
public SimpleValue(object value, bool isAttribute, bool isReadOnly)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The initial value for this SimpleValue. |
| bool | isAttribute | true if this SimpleValue is an element attribute value; false if an element's content's value. |
| bool | isReadOnly | true if this SimpleValue is intended to be read-only once the constructor has finished. |
Remarks
Constructs an element's content or attribute value from the passed string value, and also allows the caller to specify that the value is immutable. The string should be un-escaped by this point; it must not still be in the form of the CDATA construct.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If the string value is illegal. |
Properties
InternalValue
Get or set the internal value of this IXmlValue.
Declaration
protected virtual object InternalValue { get; set; }
Property Value
| Type | Description |
|---|---|
| object | The current value of this SimpleValue object or |
Remarks
This property acts as a single point to which all accessor calls route. As such, it is intended to be extended by inheriting implementations.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | If trying to set value when this IXmlValue is not mutable. |
IsAttribute
Determine if this value is an element attribute.
Declaration
public virtual bool IsAttribute { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | true if this value is an element attribute, otherwise false. |
IsContent
Determine if this value is an element's content.
Declaration
public virtual bool IsContent { get; }
Property Value
| Type | Description |
|---|---|
| bool | true if this value is an element's content, otherwise false. |
IsEmpty
Determine if the value is empty.
Declaration
public virtual bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool | true if the value is empty. |
IsMutable
Determine if this value can be modified.
Declaration
public virtual bool IsMutable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | true if this value can be modified, otherwise false to indicate that this value is read-only. |
Remarks
If the value can not be modified, all mutating methods are required to throw an InvalidOperationException.
Parent
Get or set the parent element of this value.
Declaration
public virtual IXmlElement Parent { get; set; }
Property Value
| Type | Description |
|---|---|
| IXmlElement | The parent element, or |
Remarks
The parent can not be modified once set.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the specified parent is |
| InvalidOperationException | If trying to set parent that is already set. |
Value
Get the value as an object.
Declaration
public virtual object Value { get; }
Property Value
| Type | Description |
|---|---|
| object | The value as an object or |
Remarks
The following types are supported:
- Boolean
- Integer
- Long
- Double
- Decimal
- String
- Binary
- DateTime
Methods
Clone()
Creates and returns a copy of this SimpleValue.
Declaration
public virtual object Clone()
Returns
| Type | Description |
|---|---|
| object | A clone of this instance. |
Remarks
The returned copy is "unlinked" from the parent and mutable.
Convert(object, XmlValueType)
Convert the passed object to the specified type.
Declaration
protected virtual object Convert(object o, XmlValueType type)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o | The object value. |
| XmlValueType | type | The enumerated type to convert to. |
Returns
| Type | Description |
|---|---|
| object | An object of the specified type. |
EnsureType(XmlValueType)
Change the type of the internal representation of the IXmlValue.
Declaration
protected virtual object EnsureType(XmlValueType type)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlValueType | type | The enumerated type to convert to. |
Returns
| Type | Description |
|---|---|
| object | The current value of this SimpleValue object as the specified
type or |
Remarks
A failed conversion will leave the value as null.
Equals(object)
Compare this XML value with another XML value for equality.
Declaration
public override bool Equals(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o | The object to compare to. |
Returns
| Type | Description |
|---|---|
| bool | true if the values are equal, false otherwise. |
Overrides
GetBinary()
Get the value as Binary.
Declaration
public virtual Binary GetBinary()
Returns
| Type | Description |
|---|---|
| Binary | The value as a Binary object. |
Remarks
The XML format is expected to be Base64.
GetBinary(Binary)
Get the value as Binary.
Declaration
public virtual Binary GetBinary(Binary defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Binary | defaultValue | The default return value if the internal value can not be translated into a legal value of type Binary. |
Returns
| Type | Description |
|---|---|
| Binary | The value as a Binary object. |
Remarks
The XML format is expected to be Base64.
GetBoolean()
Get the value as a boolean.
Declaration
public virtual bool GetBoolean()
Returns
| Type | Description |
|---|---|
| bool | The value as a boolean. |
GetBoolean(bool)
Get the value as a boolean.
Declaration
public virtual bool GetBoolean(bool defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | defaultValue | The default return value if the internal value can not be translated into a legal value of type boolean. |
Returns
| Type | Description |
|---|---|
| bool | The value as a boolean. |
GetDateTime()
Get the value as a DateTime.
Declaration
public virtual DateTime GetDateTime()
Returns
| Type | Description |
|---|---|
| DateTime | The value as a DateTime. |
GetDateTime(DateTime)
Get the value as a DateTime.
Declaration
public virtual DateTime GetDateTime(DateTime defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | defaultValue | The default return value if the internal value can not be translated into a legal value of type DateTime. |
Returns
| Type | Description |
|---|---|
| DateTime | The value as a DateTime. |
GetDecimal()
Get the value as a decimal.
Declaration
public virtual decimal GetDecimal()
Returns
| Type | Description |
|---|---|
| decimal | The value as a decimal. |
GetDecimal(decimal)
Get the value as a Decimal.
Declaration
public virtual decimal GetDecimal(decimal defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | defaultValue | The default return value if the internal value can not be translated into a legal value of type decimal. |
Returns
| Type | Description |
|---|---|
| decimal | The value as a Decimal. |
GetDouble()
Get the value as a double.
Declaration
public virtual double GetDouble()
Returns
| Type | Description |
|---|---|
| double | The value as a double. |
GetDouble(double)
Get the value as a double.
Declaration
public virtual double GetDouble(double defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| double | defaultValue | The default return value if the internal value can not be translated into a legal value of type double. |
Returns
| Type | Description |
|---|---|
| double | The value as a double. |
GetHashCode()
Provide a hash value for this XML value.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | The hash value for this XML value. |
Overrides
Remarks
The hash value is defined as one of the following:
- 0 if Value is
null - otherwise the hash value is the GetHashCode() of the string representation of the value
GetInt()
Get the value as an int.
Declaration
public virtual int GetInt()
Returns
| Type | Description |
|---|---|
| int | The value as an int. |
GetInt(int)
Get the value as an int.
Declaration
public virtual int GetInt(int defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | defaultValue | The default return value if the internal value can not be translated into a legal value of type int. |
Returns
| Type | Description |
|---|---|
| int | The value as an int. |
GetLong()
Get the value as a long.
Declaration
public virtual long GetLong()
Returns
| Type | Description |
|---|---|
| long | The value as a long. |
GetLong(long)
Get the value as a long.
Declaration
public virtual long GetLong(long defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| long | defaultValue | The default return value if the internal value can not be translated into a legal value of type long. |
Returns
| Type | Description |
|---|---|
| long | The value as a long. |
GetString()
Get the value as a string.
Declaration
public virtual string GetString()
Returns
| Type | Description |
|---|---|
| string | The value as a string. |
GetString(string)
Get the value as a string.
Declaration
public virtual string GetString(string defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | defaultValue | The default return value if the internal value can not be translated into a legal value of type string. |
Returns
| Type | Description |
|---|---|
| string | The value as a string. |
ReadExternal(IPofReader)
Restore the contents of a user type instance by reading its state using the specified IPofReader object.
Declaration
public virtual void ReadExternal(IPofReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| IPofReader | reader | The IPofReader from which to read the object's state. |
Exceptions
| Type | Condition |
|---|---|
| IOException | If an I/O error occurs. |
SetBinary(Binary)
Set the Binary value.
Declaration
public virtual void SetBinary(Binary val)
Parameters
| Type | Name | Description |
|---|---|---|
| Binary | val | A new value of type Binary. |
SetBoolean(bool)
Set the boolean value.
Declaration
public virtual void SetBoolean(bool val)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | val | A new value of type boolean. |
SetDateTime(DateTime)
Set the value as a DateTime.
Declaration
public virtual void SetDateTime(DateTime val)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | val | A new value of type DateTime. |
SetDecimal(decimal)
Set the decimal value.
Declaration
public virtual void SetDecimal(decimal val)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | val | A new value of type decimal. |
SetDouble(double)
Set the double value.
Declaration
public virtual void SetDouble(double val)
Parameters
| Type | Name | Description |
|---|---|---|
| double | val | A new value of type double. |
SetInt(int)
Set the int value.
Declaration
public virtual void SetInt(int val)
Parameters
| Type | Name | Description |
|---|---|---|
| int | val | A new value of type int. |
SetLong(long)
Set the long value.
Declaration
public virtual void SetLong(long val)
Parameters
| Type | Name | Description |
|---|---|---|
| long | val | A new value of type long. |
SetString(string)
Set the string value.
Declaration
public virtual void SetString(string val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | val | A new value of type string. |
ToString()
Format the XML value into a string in a display format.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of the XML value. |
Overrides
WriteExternal(IPofWriter)
Save the contents of a POF user type instance by writing its state using the specified IPofWriter object.
Declaration
public virtual void WriteExternal(IPofWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| IPofWriter | writer | The IPofWriter to which to write the object's state. |
Exceptions
| Type | Condition |
|---|---|
| IOException | If an I/O error occurs. |
WriteValue(TextWriter, bool)
Write the value as it will appear in XML.
Declaration
public virtual void WriteValue(TextWriter writer, bool isPretty)
Parameters
| Type | Name | Description |
|---|---|---|
| TextWriter | writer | A TextWriter object to use to write to. |
| bool | isPretty | true to specify that the output is intended to be as human readable as possible. |