VisiBroker for .NET Developer’s Guide : Using the dynamically managed types

Using the dynamically managed types
The DynAny interface provides a way to dynamically create basic and constructed data types at runtime. It also allows information to be interpreted and extracted from an Any object, even if the type it contains was not known to the server at compile-time. The use of the DynAny interface enables you to build powerful client and server applications that create and interpret data types at runtime.
DynAny types
A DynAny object has an associated value that may either be a basic data type (such as bool, int, or float) or a constructed data type. The DynAny interface provides methods for determining the type of the contained data as well as for setting and extracting the value of primitive data types.
Constructed data types are represented by the following interfaces, which are all derived from DynAny. Each of these interfaces provides its own set of methods that are appropriate for setting and extracting the values it contains.
Usage restrictions
A DynAny object may only be used locally by the process which created it. Any attempt to use a DynAny object as a parameter on an operation request for a bound object or to externalize it using the ObjectToString method will cause a MARSHAL exception to be raised.
Furthermore, any attempt to use a DynAny object as a parameter on DII request will cause a NO_IMPLEMENT exception to be raised.
Creating a DynAny
A DynAny object is created by invoking an operation on a DynAnyFactory object. First obtain a reference to the DynAnyFactory object, and then use that object to create the new DynAny object.
Initializing and accessing the value in a DynAny
The DynAny.Insert<Type> methods in VisiBroker for .NET allow you to initialize a DynAny object with a variety of basic data types, where <Type> is bool, octet, char, and so on. Any attempt to insert a type that does not match the TypeCode defined for the DynAny will cause an TypeMismatch exception to be raised.
The DynAny.Get<Type> methods in VisiBroker for .NET allow you to access the value contained in a DynAny object, where <Type> is bool, octet, char, and so on. Any attempt to access a value from a DynAny component which does not match the TypeCode defined for the DynAny will cause a TypeMismatch exception to be raised.
The DynAny interface also provide methods for copying, assigning, and converting to or from an Any object.
Constructed data types
The following types are derived from the DynAny interface and are used to represent constructed data types.
Traversing the components in a constructed data type
Several of the interfaces that are derived from DynAny actually contain multiple components. The DynAny interface provides methods that allow you to iterate through these components. The DynAny-derived objects that contain multiple components maintain a pointer to the current component.
Returns a DynAny object, which may be narrowed to the appropriate type, based on the component's TypeCode.
Sets the current component pointer to the component with the specified, zero-based index. Returns false if there is no component at the specified index. Sets the current component pointer to -1 (no component) if specified with a negative index.
DynEnum
This interface represents a single enumeration constant. Methods are provided for setting and obtaining the value as a string or as an integral value.
DynStruct
This interface represents a dynamically constructed struct type. The members of the structure can be retrieved or set using a sequence of NameValuePair objects. Each NameValuePair object contains the member's name and an Any containing the member's type and value.
You may use the Rewind, Next, CurrentComponent, and Seek methods to traverse the members in the structure. Methods are provided for setting and obtaining the structure's members.
DynUnion
This interface represents a union and contains two components. The first component represents the discriminator and the second represents the member value.
You may use the Rewind, Next, CurrentComponent, and Seek methods to traverse the components. Methods are provided for setting and obtaining the union's discriminator and member value.
DynSequence and DynArray
A DynSequence or DynArray represents a sequence of basic or constructed data types without the need of generating a separate DynAny object for each component in the sequence or array. The number of components in a DynSequence may be changed, while the number of components in a DynArray is fixed.
You may use the Rewind, Next, CurrentComponent, and Seek methods to traverse the members in a DynArray or DynSequence.