Message.GetField
Method
Visual Basic
Overloads Public FunctionGetField
(
ByVal fieldName As String)
Overloads Public FunctionGetField
(
ByVal messageField As MessageField,
ByVal fieldId As UInt16)
C#
public MessageFieldGetField
(
string fieldName);
public MessageFieldGetField
(
string fieldName,
ushort fieldId);
Purpose
Get a specified field from a message.
Remarks
Programs specify the field to retrieve using the fieldName
and fieldId
parameters.
The method takes a snapshot of the field, and returns that information as a MessageField object. To obtain the value of the field, programs can either extract the Value property from the MessageField object explicitly, or implicitly extract its Value by assigning the object to a variable; see Implicit Conversions.
Programs can use a related method to loop through all the fields of a message; to retrieve each field by its integer index number, see Message.GetFieldByIndex.
Parameter |
Description |
|
Get a field with this name. |
|
Get the field with this identifier. The constant |
Field Search Algorithm
This method, and related methods that get message fields, all use this algorithm to find a field within a message, as specified by a field identifier and a field name.
Procedure
1. | If the program supplied MessageField.NoSpecificId (zero) as the identifier, or omitted any identifier, then begin at step 3. |
If the program supplied a non-zero field identifier, then search for the field with that identifier.
If the search succeeds, return the field.
On failure, continue to step 2.
2. | If the identifier search (in step 1) fails, and the program supplied a non-null field name, then search for a field with that name. |
If the name search succeeds, and the identifier in the field is null, return the field.
If the name search succeeds, but the actual identifier in the field is non-null (so it does not match the identifier supplied) then throw an exception with the status code IDConflict.
On failure, or if the program supplied null as the field name, return null
.
3. | When the program supplied MessageField.NoSpecificId (zero) as the identifier, or omitted any identifier, then begin here. |
Search for a field with the specified name—even if that name is null.
If the search succeeds, return the field.
On failure, return null
.
If a message contains several fields with the same name, searching by name finds the first instance of the field with that name.
Extracting Fields from a Nested Message
Earlier releases of Rendezvous software allowed programs to get fields from a nested submessage by concatenating field names. Starting with release 6, Rendezvous software no longer supports this special case convenience. Instead, programs must separately extract the nested submessage using Message.GetField (or a related method), and then get the desired fields from the submessage.
Method Forms
With only a field name, find the field by name. If the field name is not present in the message, return null. If several fields with that name are present in the message, this method returns the first one that it finds.
With only a field identifier, find the field with that identifier (since identifiers are unique, the message can contain at most one such field). If the identifier is not present in the message, return null.
With both a field name and a field identifier, search first by identifier, and then by field name. If neither are present in the message, return null. If identifier search succeeds, return the field value. If the name search succeeds, but the actual identifier in the field is non-zero (so it does not match the identifier supplied) then throw a RendezvousException with status code IDConflict.