Click or drag to resize
Element Class
Elements are used to represent all data sent to/received from API services.
Inheritance Hierarchy
SystemObject
  Bloomberglp.BlpapiElement

Namespace:  Bloomberglp.Blpapi
Assembly:  Bloomberglp.Blpapi (in Bloomberglp.Blpapi.dll) Version: 3.24.11.1
Syntax
public abstract class Element : ICloneable

The Element type exposes the following members.

Constructors
  NameDescription
Protected methodElement
Initializes a new instance of the Element class
Top
Properties
  NameDescription
Public propertyDatatype
Gets the Datatype of this Element.
Public propertyElementDefinition
Gets a reference to the read-only element definition object that defines the properties of this elements value.
Public propertyElements
Gets an enumerable collection of all sub-elements.
Public propertyIsArray
Gets true if this element is an array.
Public propertyIsComplexType
Indicates whether this element is a complex type.
Public propertyIsNull
Gets true if this element is null (has no values).
Public propertyIsReadOnly
Gets true if this element can not be modified.
Public propertyItemInt32
This is the same as GetValue(index).
Public propertyItemString Obsolete.
This is the same as GetElement(name).
Public propertyItemName
This is the same as GetElement(name).
Public propertyItemString, Int32 Obsolete.
This is the same as GetElement(name). GetValue(index).
Public propertyItemName, Int32
This is the same as GetElement(name). GetValue(index).
Public propertyName
Gets the name of this element.
Public propertyNumElements
Gets the number of elements this element contains.
Public propertyNumValues
Gets the number of values this element contains.
Public propertyTypeDefinition
Gets the SchemaTypeDefinition for this element.
Top
Methods
  NameDescription
Public methodAppendElement
If this Element is an array of Sequence or Choice Elements, appends a default initialized element to this element and return the appended element.
Public methodAppendValue(Boolean)
Appends the specified value to this array element.
Public methodAppendValue(Byte) Obsolete.
Appends the specified value to this array element. Deprecated. Arrays of byte arrays are not supported. This method will always throw an NotSupportedException.
Public methodAppendValue(Char)
Appends the specified value to this array element.
Public methodAppendValue(Double)
Appends the specified value to this array element.
Public methodAppendValue(Int32)
Appends the specified value to this array element.
Public methodAppendValue(Int64)
Appends the specified value to this array element.
Public methodAppendValue(Single)
Appends the specified value to this array element.
Public methodAppendValue(String)
Appends the specified value to this array element.
Public methodAppendValue(Constant)
Appends the specified value to this array element.
Public methodAppendValue(Datetime)
Appends the specified value to this array element.
Public methodAppendValue(Name)
Appends the specified value to this array element.
Public methodClone
Clone this element.
Public methodFindConstant(ConstantsList)
Finds the constant in a ConstantList that is equal to the value of this element.
Public methodFindConstant(ConstantsList, Int32)
Gets the constant in a ConstantList that is equal to the value at the specified index of this element.
Public methodGetChoice
Returns the selected choice if this is a choice type.
Public methodGetElement(Int32)
Returns the sub-element at the specified zero based position.
Public methodGetElement(String) Obsolete.
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable. Deprecated, use GetElement(Name) instead.
Public methodGetElement(Name)
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable.
Public methodGetElementAsBool(String) Obsolete.
Returns the value of the named sub-element as a boolean. Deprecated, use GetElementAsBool(Name) instead.
Public methodGetElementAsBool(Name)
Returns the value of the named sub-element as a boolean.
Public methodGetElementAsBytes(String) Obsolete.
Returns the value of the named sub-element as a byte array. Deprecated, use GetElementAsBytes(Name) instead.
Public methodGetElementAsBytes(Name)
Returns the value of the named sub-element as a byte array.
Public methodGetElementAsChar(String) Obsolete.
Returns the value of the named sub-element as a char. Deprecated, use GetElementAsChar(Name) instead.
Public methodGetElementAsChar(Name)
Returns the value of the named sub-element as a char.
Public methodGetElementAsDate(String) Obsolete.
Returns the value of the named sub-element as a Date. Deprecated, use GetElementAsDate(Name) instead.
Public methodGetElementAsDate(Name)
Returns the value of the named sub-element as a Date.
Public methodGetElementAsDatetime(String) Obsolete.
Returns the value of the named sub-element as a Datetime. Deprecated, use GetElementAsDatetime(Name) instead.
Public methodGetElementAsDatetime(Name)
Returns the value of the named sub-element as a Datetime.
Public methodGetElementAsFloat32(String) Obsolete.
Returns the value of the named sub-element as a float. Deprecated, use GetElementAsFloat32(Name) instead.
Public methodGetElementAsFloat32(Name)
Returns the value of the named sub-element as a float.
Public methodGetElementAsFloat64(String) Obsolete.
Returns the value of the named sub-element as a double. Deprecated, use GetElementAsFloat64(Name) instead.
Public methodGetElementAsFloat64(Name)
Returns the value of the named sub-element as a double.
Public methodGetElementAsInt32(String) Obsolete.
Returns the value of the named sub-element as an int. Deprecated, use GetElementAsInt32(Name) instead.
Public methodGetElementAsInt32(Name)
Returns the value of the named sub-element as an int.
Public methodGetElementAsInt64(String) Obsolete.
Returns the value of the named sub-element as a long. Deprecated, use GetElementAsInt64(Name) instead.
Public methodGetElementAsInt64(Name)
Returns the value of the named sub-element as a long.
Public methodGetElementAsName(String) Obsolete.
Returns the value of the named sub-element as a Name. Deprecated, use GetElementAsName(Name) instead.
Public methodGetElementAsName(Name)
Returns the value of the named sub-element as a Name.
Public methodGetElementAsString(String) Obsolete.
Returns the value of the named sub-element as a string. Deprecated, use GetElementAsString(Name) instead.
Public methodGetElementAsString(Name)
Returns the value of the named sub-element as a string.
Public methodGetElementAsTime(String) Obsolete.
Returns the value of the named sub-element as a Time. Deprecated, use GetElementAsTime(Name) instead.
Public methodGetElementAsTime(Name)
Returns the value of the named sub-element as a Time.
Public methodGetValue
Returns the value of this element as an object.
Public methodGetValue(Int32)
Returns the value of the element at the specified index as an object.
Public methodGetValueAsBool
Returns the value of this element as a boolean.
Public methodGetValueAsBool(Int32)
Returns the value of the element at the specified index as a boolean.
Public methodGetValueAsBytes
Returns the value of this element as a byte array.
Public methodGetValueAsBytes(Int32)
Returns the value of this element at the specified index as a byte array.
Public methodGetValueAsChar
Returns the value of this element as a char.
Public methodGetValueAsChar(Int32)
Returns the value of this element at the specified index as a char.
Public methodGetValueAsDate
Returns the value of this element as a Date.
Public methodGetValueAsDate(Int32)
Returns the value of this element at the specified index as a Date.
Public methodGetValueAsDatetime
Returns the value of this element as a Datetime.
Public methodGetValueAsDatetime(Int32)
Returns the value of this element at the specified index as a Datetime.
Public methodGetValueAsElement
Returns the value of this element as an Element.
Public methodGetValueAsElement(Int32)
Returns the value at the specified index in this element as an Element.
Public methodGetValueAsEnumeration
Returns the value of this element as a Enumeration constant.
Public methodGetValueAsEnumeration(Int32)
Returns the value of this element at the specified index as an Enumeration constant.
Public methodGetValueAsFloat32
Returns the value of this element as a float.
Public methodGetValueAsFloat32(Int32)
Returns the value of this element at the specified index as a float.
Public methodGetValueAsFloat64
Returns the value of this element as a double.
Public methodGetValueAsFloat64(Int32)
Returns the value of this element at the specified index as a double.
Public methodGetValueAsInt32
Returns the value of this element as an int.
Public methodGetValueAsInt32(Int32)
Returns the value of this element at the specified index as an int.
Public methodGetValueAsInt64
Returns the value of this element as a long.
Public methodGetValueAsInt64(Int32)
Returns the value of this element at the specified index as a long.
Public methodGetValueAsName
Returns the value of this element as a Enumeration constant.
Public methodGetValueAsName(Int32)
Returns the value of this element at the specified index as an Enumeration constant.
Public methodGetValueAsString
Returns the value of this element as a string.
Public methodGetValueAsString(Int32)
Returns the value of this element at the specified index as a string.
Public methodGetValueAsTime
Returns the value of this element as a Time.
Public methodGetValueAsTime(Int32)
Returns the value of this element at the specified index as a Time.
Public methodHasElement(String) Obsolete.
Returns true if this element contains an element with the specified name. Deprecated, use HasElement(Name) instead.
Public methodHasElement(Name)
Returns true if this element contains an element with the specified name.
Public methodHasElement(String, Boolean) Obsolete.
Returns true if this element contains an element with the specified name. Deprecated, use HasElement(Name, Boolean) instead.
Public methodHasElement(Name, Boolean)
Returns true if this element contains an element with the specified name.
Public methodIsEqualTo(Constant)
Gets true if the value this element is equal to the specified constant.
Public methodIsEqualTo(Constant, Int32)
Gets true if the value at the specified index of this element is equal to the specified constant.
Public methodIsNullValue
Gets true if the sub-element at the specified position in a sequence or choice element is null.
Public methodPrint(Stream)
Prints the contents of this element to the specified Stream.
Public methodPrint(TextWriter)
Prints the contents of this element to the specified TextWriter.
Public methodSetChoice(String) Obsolete.
Sets the named sub-element as the choice's selection. Deprecated, use SetChoice(Name) instead.
Public methodSetChoice(Name)
Sets the named sub-element as the choice's selection.
Public methodSetElement(String, Constant) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Constant) instead.
Public methodSetElement(String, Datetime) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Datetime) instead.
Public methodSetElement(String, Name) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Name) instead.
Public methodSetElement(String, Boolean) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Boolean) instead.
Public methodSetElement(String, Byte) Obsolete.
Public methodSetElement(String, Char) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Char) instead.
Public methodSetElement(String, Double) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Double) instead.
Public methodSetElement(String, Int32) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Int32) instead.
Public methodSetElement(String, Int64) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Int64) instead.
Public methodSetElement(String, Single) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, Single) instead.
Public methodSetElement(String, String) Obsolete.
Sets the named sub-element to the specified value. Deprecated, use SetElement(Name, String) instead.
Public methodSetElement(Name, Constant)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Datetime)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Name)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Boolean)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Byte)
Public methodSetElement(Name, Char)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Double)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Int32)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Int64)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, Single)
Sets the named sub-element to the specified value.
Public methodSetElement(Name, String)
Sets the named sub-element to the specified value.
Public methodSetValue(Boolean)
Sets the value of this element to the specified value.
Public methodSetValue(Byte)
Sets the value of this element to the specified value.
Public methodSetValue(Char)
Sets the value of this element to the specified value.
Public methodSetValue(Double)
Sets the value of this element to the specified value.
Public methodSetValue(Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Int64)
Sets the value of this element to the specified value.
Public methodSetValue(Single)
Sets the value of this element to the specified value.
Public methodSetValue(String)
Sets the value of this element to the specified value.
Public methodSetValue(Constant)
Sets the value of this element to the specified value.
Public methodSetValue(Datetime)
Sets the value of this element to the specified value.
Public methodSetValue(Name)
Sets the value of this element to the specified value.
Public methodSetValue(Boolean, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Byte, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Char, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Double, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Int32, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Int64, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Single, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(String, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Constant, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Datetime, Int32)
Sets the value of this element to the specified value.
Public methodSetValue(Name, Int32)
Sets the value of this element to the specified value.
Public methodToString
Return the string representation of this object.
(Overrides ObjectToString.)
Public methodValueIsNull Obsolete.
Gets true if the element at the specified position in a sequence or choice element is null.
Top
Remarks

Using "Element" objects

An element is a variant type. That is they can represent any of the data types supported by the blpapi. Elements can represent simple scalar values like (float, string), arrays of simple types, complex values (sequences/choices), and arrays of complex values.

Accessing Elements

Elements are used when accessing messages received from the API, and when preparing requests for API services. There are two classes of accessor/manipulators that are used to access/manipulate elements. When accessing simple values and arrays, the "GetValueAsX" family of functions are used where 'X' is the target data type(e.g., "GetValueAsInt32"). For simplicity, all "GetValueAsX" functions can optionally be supplied with an index parameter to access elements of an array. For scalar elements, index should not be supplied, or zero should be supplied. The following are examples of accessing simple and array elements.

This example shows how to access the value of a scalar element as an integer number. Then goes on to show how to access the same element as a String

Element e;

...

int x = e.GetValueAsIn32();

System.Console.WriteLine(e.GetValueAsString());

(or)

System.Console.WriteLine(e.GetValueAsString(0));

The following example shows how to access array elements

int count = e.NumValues;
for (int i = 0; i < count; ++i) {
System.Console.WriteLine(e.GetValueAsString(i));
}

Use NumValues to determine the number of values available. For scalar values, it will return either 0 or 1. For arrays it will return the actual number of values in the array.

Complex elements contain named sub-elements. Sub-elements are accessed using the "GetElement", and "GetElementAsX" accessor functions. To demonstrate, the following example shows how to access the "city" sub-element of an "address" element:

private static readonly Name City = Name.GetName("city");

Element address;
...
address.GetElement(City);

The following example retrieves the value of the "city" sub-element as a string value.

address.GetElementAsString(City);

To determine the number of available sub elements in a given element, the "NumElements" accessor can be used. To retrieve the Nth available sub-element of a complex element, the "GetElement(int)" accessor can be used. For example:

int numElements = address.NumElements;
for (int i = 0; i < numElements; ++i) {
Element e = address.GetElement(i);
System.Console.WriteLine($"{e.Name}={e.GetValueAsString()}");
}

Manipulating Elements

Elements are also used to submit input for API services (e.g., preparing a reference data request). Just as when accessing element values, there are two types of manipulators used to set elements. To set the value of simple elements, and arrays of simple elements, the "SetValue", and "AppendValue" manipulator are used. For example

private static readonly Name Security = Name.GetName("security");
private static readonly Name Fields = Name.GetName("fields");

Request request;
...
Element security = request.GetElement(Security);
security.SetValue("IBM UN Equity");

Element fields = request.GetElement(Fields);
fields.AppendValue("DS003");
fields.AppendValue("PX_LAST");
To directly set named sub-elements, use the "SetElement" manipulator:

request.SetElement(Security, "IBM UN Equity");

Type Conversions

The API will convert data types as long as there is no loss of precision involved. So
- A BOOL can be returned as bool, char, Int32, Int64, Float32, Float64, String (the string will be "true" or "false")
- A BOOL can be set from bool, String (if it has a value of "y", "n", "yes", "no", "true" or "false")
- A CHAR can be returned as char, Int32, Int64, Float32, Float64, String
- A CHAR can be set from char
- An INT32 can be returned as Int32, Int64, Float64, String
- An INT32 can be set from char, Int32
- An INT64 can be returned as Int64, String
- An INT64 can be set from char, Int32, Int64
- A FLOAT32 can be returned as Float32, Float64, String
- A FLOAT32 can be set from char, Float32
- A FLOAT64 can be returned as Float64, String
- A FLOAT64 can be set from char, Float32, Float64
- A BYTEARRAY can be set from byte[] and returned as byte[] ONLY

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also