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.13.2.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
Gets true if 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
This is the same as GetElement(name).
Public propertyItemName
This is the same as GetElement(name).
Public propertyItemString, Int32
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)
Appends the specified value to this array element.
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)
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable.
Public methodGetElement(Name)
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable.
Public methodGetElementAsBool(String)
Returns the value of the named sub-element as a boolean.
Public methodGetElementAsBool(Name)
Returns the value of the named sub-element as a boolean.
Public methodGetElementAsBytes(String)
Returns the value of the named sub-element as a byte array.
Public methodGetElementAsBytes(Name)
Returns the value of the named sub-element as a byte array.
Public methodGetElementAsChar(String)
Returns the value of the named sub-element as a char.
Public methodGetElementAsChar(Name)
Returns the value of the named sub-element as a char.
Public methodGetElementAsDate(String)
Returns the value of the named sub-element as a Date.
Public methodGetElementAsDate(Name)
Returns the value of the named sub-element as a Date.
Public methodGetElementAsDatetime(String)
Returns the value of the named sub-element as a Datetime.
Public methodGetElementAsDatetime(Name)
Returns the value of the named sub-element as a Datetime.
Public methodGetElementAsFloat32(String)
Returns the value of the named sub-element as a float.
Public methodGetElementAsFloat32(Name)
Returns the value of the named sub-element as a float.
Public methodGetElementAsFloat64(String)
Returns the value of the named sub-element as a double.
Public methodGetElementAsFloat64(Name)
Returns the value of the named sub-element as a double.
Public methodGetElementAsInt32(String)
Returns the value of the named sub-element as an int.
Public methodGetElementAsInt32(Name)
Returns the value of the named sub-element as an int.
Public methodGetElementAsInt64(String)
Returns the value of the named sub-element as a long.
Public methodGetElementAsInt64(Name)
Returns the value of the named sub-element as a long.
Public methodGetElementAsName(String)
Returns the value of the named sub-element as a Name.
Public methodGetElementAsName(Name)
Returns the value of the named sub-element as a Name.
Public methodGetElementAsString(String)
Returns the value of the named sub-element as a string.
Public methodGetElementAsString(Name)
Returns the value of the named sub-element as a string.
Public methodGetElementAsTime(String)
Returns the value of the named sub-element as a Time.
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)
Returns true if this element contains an element with the specified name.
Public methodHasElement(Name)
Returns true if this element contains an element with the specified name.
Public methodHasElement(String, Boolean)
Returns true if this element contains an element with the specified name.
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)
Sets the named sub-element as the choice's selection.
Public methodSetChoice(Name)
Sets the named sub-element as the choice's selection.
Public methodSetElement(String, Constant)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Datetime)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Name)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Boolean)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Byte)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Char)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Double)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Int32)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Int64)
Sets the named sub-element to the specified value.
Public methodSetElement(String, Single)
Sets the named sub-element to the specified value.
Public methodSetElement(String, String)
Sets the named sub-element to the specified value.
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:

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

Request request;
...
Element securitiy = 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");

Methods which specify a Element name come in two forms. One which takes a Name as a parameter and one which takes a String. The form which takes Name is more efficient. However, it requires the Name to have been created in the global name table.

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

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