For example, an IDL interface whose name is fooHelper is mapped to C# class
_fooHelper, regardless of whether an interface named
foo exists. The helper class for C# class
_fooHelper is named
_fooHelperHelper.
The C# null may only be used to represent null CORBA object references and valuetypes (including recursive valuetypes). For example, a zero length string, rather than
null must be used to represent the empty string. This is also true for arrays and any constructed type, except for valuetypes. If you attempt to pass a
null for a structure, it will raise a system
NullReferenceException.
The IDL type boolean is mapped to the C# type
bool. The IDL constants
TRUE and
FALSE are mapped to the C# constants
true and
false.
The IDL type string, both bounded and unbounded variants, is mapped to the C# type
string. Range checking for characters in the string as well as bounds checking of the string are done at marshal time.
The IDL type wstring, used to represent Unicode strings, is mapped to the C# type
string. Bounds checking of the string is done at marshal time.
1 VisiBroker for .NET might support it in a future release of the OMG standard implementation.
2 UNICODE is used “on the wire.”
|
IDL constructed types include enum,
struct,
union,
sequence, and
array. The types
sequence and
array are both mapped to the C#
array type. The IDL constructed types
enum,
struct, and
union are mapped to a C# class that implements the semantics of the IDL type. The C# class generated will have the same name as the original IDL type.
An IDL enum is mapped to a C# enum with the same name as the enum type which declares the enum values. The code sample below is an example of an IDL enum mapped to a C# enum.
An IDL struct is mapped to a C# class with the same name that provides instance variables for the fields in IDL member ordering and a constructor for all values.
An IDL union is mapped to a sealed C# class of the same name. It provides the following:
If the branch corresponds to the default case label, then the modifier method sets the discriminant to a value that does not match any other case labels.
A default method _default() is created if there is no explicit default case label, and the set of case labels does not completely cover the possible values of the discriminant. It will set the value of the union to be an out-of-range value.
An IDL sequence is mapped to a C# array. In the mapping, anywhere the sequence type is needed, an array of the mapped type of the sequence element is used.
An IDL array is mapped in the same way as an IDL bounded sequence. In the mapping, anywhere the array type is needed, an array of the mapped type of array element is used. In C#, the natural C# subscripting operator is applied to the mapped array. The length of the array can be made available in C#, by bounding the array with an IDL constant, which will be mapped as per the rules for constants.
Given a user-defined type named Foo, the
idl2cs compiler generates the following:
There are no special “nil” object references. C# null can be passed freely wherever an object reference is expected.
In the example above, the two interfaces, Foo and
FooOperations, provide the complete signature of your IDL interface when mapped to C#.
The signature interface defines the signature for each interface you declare in your IDL file, while the Operations interface provides the implementation details.
The Operations interface contains only the operations and attributes declared in the IDL interfaces. The C# Operations interface contains the mapped operation signatures. Methods can be invoked on an object reference to this interface.
A Helper class is provided for most of the classes in the CORBA namespace. They are also generated by the
idl2cs compiler for user-defined types and are given the name of the class that is generated for the type with an additional
Helper suffix. The reason for using the
Helper class is to avoid loading the methods that the class offers if they are not needed. Several static methods needed to manipulate the type are supplied.
The Helper class declares a static narrow method that allows an instance of
CORBA.Object to be narrowed to the object reference of a more specific type. The IDL exception
CORBA::BAD_PARAM is thrown if the narrow fails because the object reference doesn't support the request type. A different system exception is raised to indicate other kinds of errors. Trying to narrow a null will always succeed with a return value of null.
For objects like mapped structures, enumerations, unions, exceptions, valuetypes, and valueboxes, the Helper class provides methods for reading and writing the object to a stream and returning the object's repository identifier. The
Helper classes generated for interfaces contain additional methods, like
bind and
narrow.
A stub class is generated by the idl2cs compiler to provide a stub implementation for
<interface_name> which the client calls. This class provides the implementation for transparently acting on an object implementation.
User-defined exceptions are mapped to C# classes that extend CORBA.UserException and are otherwise mapped just like the IDL
struct type, including the generation of
Helper classes.
The standard IDL system exceptions are mapped to final C# classes that extend CORBA.SystemException and provide access to the IDL major and minor exception code, as well as a string describing the reason for the exception. There are no public constructors for
CORBA.SystemException; only classes that extend it can be instantiated.
The C# class name for each standard IDL exception is the same as its IDL name and is declared to be in the CORBA namespace. The default constructor supplies 0 for the minor code,
COMPLETED_NO for the completion code, and the empty string (“”) for the reason string. There is also a constructor which takes the reason and uses defaults for the other fields, as well as one which requires all three parameters to be specified.
The IDL type Any maps to the C# class
CORBA.Any. This class has all the necessary methods to insert and extract instances of predefined types. If the extraction operations have a mismatched type, the
CORBA::BAD_OPERATION exception is thrown.
Setting the typecode via the type() accessor wipes out the value. An attempt to extract before the value is set will result in a
CORBA::BAD_OPERATION exception being raised. This operation is provided primarily so that the type may be set properly for IDL
out parameters.