Bloomberg API for .NET
Element Class
NamespacesBloomberglp.BlpapiElement
Elements are used to represent all data sent to/received from API services.
Declaration Syntax
C#Visual BasicVisual C++
public abstract class Element : ICloneable
Public MustInherit Class Element
	Implements ICloneable
public ref class Element abstract : ICloneable
Members
All MembersConstructorsMethodsProperties



IconMemberDescription
Element()()()()
Initializes a new instance of the Element class

AppendElement()()()()
If this Element is an array of Sequence or Choice Elements, appends a default initialized element to this element and return the appended element.

AppendValue(Boolean)
Appends the specified value to this array element.

AppendValue(Char)
Appends the specified value to this array element.

AppendValue(Int32)
Appends the specified value to this array element.

AppendValue(Int64)
Appends the specified value to this array element.

AppendValue(Double)
Appends the specified value to this array element.

AppendValue(Single)
Appends the specified value to this array element.

AppendValue(Datetime)
Appends the specified value to this array element.

AppendValue(Constant)
Appends the specified value to this array element.

AppendValue(Name)
Appends the specified value to this array element.

AppendValue(String)
Appends the specified value to this array element.

AppendValue(array<Byte>[]()[][])
Appends the specified value to this array element.

Clone()()()()
Datatype
Gets the Datatype of this Element.

ElementDefinition
Gets a reference to the read-only element definition object that defines the properties of this elements value.

Elements
Gets an enumerable collection of all sub-elements.

FindConstant(ConstantsList)
Finds the constant in a ConstantList that is equal to the value of this element.

FindConstant(ConstantsList, Int32)
Gets the constant in a ConstantList that is equal to the value at the specified index of this element.

GetChoice()()()()
Returns the selected choice if this is a choice type.

GetElement(Int32)
Returns the sub-element at the specified zero based position.

GetElement(Name)
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable.

GetElement(String)
Returns the named sub-element, creating it if it doesn't exist and this element is modifiable.

GetElementAsBool(Name)
Returns the value of the named sub-element as a boolean.

GetElementAsBool(String)
Returns the value of the named sub-element as a boolean.

GetElementAsBytes(Name)
GetElementAsBytes(String)
GetElementAsChar(Name)
Returns the value of the named sub-element as a char.

GetElementAsChar(String)
Returns the value of the named sub-element as a char.

GetElementAsDate(Name)
Returns the value of the named sub-element as a Date.

GetElementAsDate(String)
Returns the value of the named sub-element as a Date.

GetElementAsDatetime(Name)
Returns the value of the named sub-element as a Datetime.

GetElementAsDatetime(String)
Returns the value of the named sub-element as a Datetime.

GetElementAsFloat32(Name)
Returns the value of the named sub-element as a float.

GetElementAsFloat32(String)
Returns the value of the named sub-element as a float.

GetElementAsFloat64(Name)
Returns the value of the named sub-element as a double.

GetElementAsFloat64(String)
Returns the value of the named sub-element as a double.

GetElementAsInt32(Name)
Returns the value of the named sub-element as an int.

GetElementAsInt32(String)
Returns the value of the named sub-element as an int.

GetElementAsInt64(Name)
Returns the value of the named sub-element as a long.

GetElementAsInt64(String)
Returns the value of the named sub-element as a long.

GetElementAsName(Name)
Returns the value of the named sub-element as a Name.

GetElementAsName(String)
Returns the value of the named sub-element as a Name.

GetElementAsString(Name)
Returns the value of the named sub-element as a string.

GetElementAsString(String)
Returns the value of the named sub-element as a string.

GetElementAsTime(Name)
Returns the value of the named sub-element as a Time.

GetElementAsTime(String)
Returns the value of the named sub-element as a Time.

GetValue()()()()
Returns the value of this element as an object.

GetValue(Int32)
Returns the value of the element at the specified index as an object.

GetValueAsBool()()()()
Returns the value of this element as a boolean.

GetValueAsBool(Int32)
Returns the value of the element at the specified index as a boolean.

GetValueAsBytes()()()()
Returns the value of this element as a byte array.

GetValueAsBytes(Int32)
Returns the value of this element at the specified index as a byte array.

GetValueAsChar()()()()
Returns the value of this element as a char.

GetValueAsChar(Int32)
Returns the value of this element at the specified index as a char.

GetValueAsDate()()()()
Returns the value of this element as a Date.

GetValueAsDate(Int32)
Returns the value of this element at the specified index as a Date.

GetValueAsDatetime()()()()
Returns the value of this element as a Datetime.

GetValueAsDatetime(Int32)
Returns the value of this element at the specified index as a Datetime.

GetValueAsElement()()()()
Returns the value of this element as an Element.

GetValueAsElement(Int32)
Returns the value at the specified index in this element as an Element.

GetValueAsEnumeration()()()()
Returns the value of this element as a Enumeration constant.

GetValueAsEnumeration(Int32)
Returns the value of this element at the specified index as an Enumeration constant.

GetValueAsFloat32()()()()
Returns the value of this element as a float.

GetValueAsFloat32(Int32)
Returns the value of this element at the specified index as a float.

GetValueAsFloat64()()()()
Returns the value of this element as a double.

GetValueAsFloat64(Int32)
Returns the value of this element at the specified index as a double.

GetValueAsInt32()()()()
Returns the value of this element as an int.

GetValueAsInt32(Int32)
Returns the value of this element at the specified index as an int.

GetValueAsInt64()()()()
Returns the value of this element as a long.

GetValueAsInt64(Int32)
Returns the value of this element at the specified index as a long.

GetValueAsName()()()()
Returns the value of this element as a Enumeration constant.

GetValueAsName(Int32)
Returns the value of this element at the specified index as an Enumeration constant.

GetValueAsString()()()()
Returns the value of this element as a string.

GetValueAsString(Int32)
Returns the value of this element at the specified index as a string.

GetValueAsTime()()()()
Returns the value of this element as a Time.

GetValueAsTime(Int32)
Returns the value of this element at the specified index as a Time.

HasElement(Name)
Returns true if this element contains an element with the specified name.

HasElement(Name, Boolean)
Returns true if this element contains an element with the specified name.

HasElement(String)
Returns true if this element contains an element with the specified name.

HasElement(String, Boolean)
Returns true if this element contains an element with the specified name.

IsArray
Gets true if this element is an array.

IsComplexType
Gets true if this element is a complex type.

IsEqualTo(Constant)
Gets true if the value this element is equal to the specified constant.

IsEqualTo(Constant, Int32)
Gets true if the value at the specified index of this element is equal to the specified constant.

IsNull
Gets true if this element is null (has no values).

IsNullValue(Int32)
Gets true if the sub-element at the specified position in a sequence or choice element is null.

IsReadOnly
Gets true if this element can not be modified.

Item[([( Name])])
This is the same as GetElement(name).

Item[([( String])])
This is the same as GetElement(name).

Item[([( Int32])])
This is the same as GetValue(index).

Item[([( Name, Int32])])
This is the same as GetElement(name). GetValue(index).

Item[([( String, Int32])])
This is the same as GetElement(name). GetValue(index).

Name
Gets the name of this element.

NumElements
Gets the number of elements this element contains.

NumValues
Gets the number of values this element contains.

Print(Stream)
Prints the contents of this element to the specified Stream.

Print(TextWriter)
Prints the contents of this element to the specified TextWriter.

SetChoice(Name)
Sets the named sub-element as the choice's selection.

SetChoice(String)
Sets the named sub-element as the choice's selection.

SetElement(Name, Boolean)
Sets the named sub-element to the specified value.

SetElement(String, Boolean)
Sets the named sub-element to the specified value.

SetElement(Name, Char)
Sets the named sub-element to the specified value.

SetElement(String, Char)
Sets the named sub-element to the specified value.

SetElement(Name, Int32)
Sets the named sub-element to the specified value.

SetElement(String, Int32)
Sets the named sub-element to the specified value.

SetElement(Name, Int64)
Sets the named sub-element to the specified value.

SetElement(String, Int64)
Sets the named sub-element to the specified value.

SetElement(Name, Double)
Sets the named sub-element to the specified value.

SetElement(String, Double)
Sets the named sub-element to the specified value.

SetElement(Name, Single)
Sets the named sub-element to the specified value.

SetElement(String, Single)
Sets the named sub-element to the specified value.

SetElement(Name, Datetime)
Sets the named sub-element to the specified value.

SetElement(String, Datetime)
Sets the named sub-element to the specified value.

SetElement(Name, Constant)
Sets the named sub-element to the specified value.

SetElement(String, Constant)
Sets the named sub-element to the specified value.

SetElement(Name, Name)
Sets the named sub-element to the specified value.

SetElement(String, Name)
Sets the named sub-element to the specified value.

SetElement(Name, String)
Sets the named sub-element to the specified value.

SetElement(String, String)
Sets the named sub-element to the specified value.

SetElement(Name, array<Byte>[]()[][])
SetElement(String, array<Byte>[]()[][])
Sets the named sub-element to the specified value.

SetValue(Boolean)
Sets the value of this element to the specified value.

SetValue(Boolean, Int32)
Sets the value of this element to the specified value.

SetValue(Char)
Sets the value of this element to the specified value.

SetValue(Char, Int32)
Sets the value of this element to the specified value.

SetValue(Int32)
Sets the value of this element to the specified value.

SetValue(Int32, Int32)
Sets the value of this element to the specified value.

SetValue(Int64)
Sets the value of this element to the specified value.

SetValue(Int64, Int32)
Sets the value of this element to the specified value.

SetValue(Double)
Sets the value of this element to the specified value.

SetValue(Double, Int32)
Sets the value of this element to the specified value.

SetValue(Single)
Sets the value of this element to the specified value.

SetValue(Single, Int32)
Sets the value of this element to the specified value.

SetValue(Datetime)
Sets the value of this element to the specified value.

SetValue(Datetime, Int32)
Sets the value of this element to the specified value.

SetValue(Constant)
Sets the value of this element to the specified value.

SetValue(Constant, Int32)
Sets the value of this element to the specified value.

SetValue(Name)
Sets the value of this element to the specified value.

SetValue(Name, Int32)
Sets the value of this element to the specified value.

SetValue(String)
Sets the value of this element to the specified value.

SetValue(String, Int32)
Sets the value of this element to the specified value.

SetValue(array<Byte>[]()[][])
SetValue(array<Byte>[]()[][], Int32)
ToString()()()() (Overrides Object.ToString()()()().)
TypeDefinition
Gets the SchemaTypeDefinition for this element.

ValueIsNull(Int32) Obsolete.
Gets true if the element at the specified position in a sequence or choice element is null.

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

 Copy imageCopy
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

 Copy imageCopy
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:

 Copy imageCopy
Element address;
...
address.GetElement("city");

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

 Copy imageCopy
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:

 Copy imageCopy
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

 Copy imageCopy
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
Static members of this type are safe for multi-threaded operations. Instance members of this type are not safe for multi-threaded operations.
Inheritance Hierarchy
Object
Element

Assembly: Bloomberglp.Blpapi (Module: Bloomberglp.Blpapi.dll) Version: 3.7.4.1