where value is
true for types that are exposed to COM clients, and
false for all other types.
Although the default COM visibility provided by the compiler is adequate for most applications, there are cases where it may be desirable to fine-tune to COM visibility of certain types. All ComVisible declarations include the fully-scoped type name immediately prior to the visibility value of true or
false. It should be straightforward to write regular expressions to modify the visibility of individual types. VisiBroker for .NET compilers do not generate COM visibility attribute for type data members and you may need to fine tune this to control visibility of class data members. Also note that static and const members of a type are not COM visible.
Microsoft recommends using user-defined interfaces as a more robust alternative to using ClassInterfaceType.AutoDual on implementation classes, where the implementation class is likely to change over time. It is also suggested to mark the implementation classes with
ClassInterfaceType.None ClassInterface attribute to avoid generation of the
_<impl class> interface (which becomes the [default] interface otherwise.) The user-defined interfaces can be inspected and appropriately marked with
ComInterfaceType.InterfaceIsDual InterfaceType attribute if necessary to generate dual interface COM servers.
At this time VisiBroker for .NET compilers do not explicitly mark classes with ClassInterfaceType.None. Neither are interfaces marked with
InterfaceIsDual. VisiBroker for .NET compilers generate AutoDual flags for public implementation classes that are generated or Java based.
By default, if we run the VisiBroker for .NET java2cs compiler over this class (with the -COM flag enabled), we will produce the following C# class:
This class is COM visible, and has getter methods for Symbol and
Price. Mark this interface with the appropriate ComInterfaceType attribute to specify dual or dispatch interface or IUnknown as required.
The next step is to tell the VisiBroker for .NET compiler not to generate the Quote interface, since we are providing our own implementation. This is done by introducing a hint file, which contains the following hint:
This hint indicates that the Java type Quote maps to a pair of C# types: a signature type
Quote, and an implementation type
QuoteImpl. We also specify that we will be using the
automatic code-generation mode. (In fact, the
<mode/> element can be omitted, as
automatic is the default code-generation mode.)
The XML element <cs-sig-type/> indicates the type name that will be used when clients interact with a Quote. The XML element <cs-impl-type/> indicates the type that will be used to implement the
Quote (for example,
QuoteImpl).
The user must then provide implementations of both the public Quote type and the internal
QuoteImpl type. The
Quote interface was listed above. Below is the
QuoteImpl:
An alternate technique is available for implementing the QuoteImpl class, if it is desirable to not have to “repeat” the serializable fields. In such cases, it is possible to implement the
QuoteImpl by extending the generated class
QuoteValueData:
Note that this class does not declare the fields Symbol and
Price, as these fields are “inherited” from the base class
QuoteValueData.
This method takes an array of strings as a parameter, and returns an array of
integers, where each element in the result indicates the length of the corresponding input string. So, if this method is called as follows:
This method signature substitutes the type object for all array-valued parameters and/or return values. (Note that this method is technically not overloaded with respect to the original method
GetLengths, since we append the suffix
ForCom to the original method name. We cannot use true overloading because C# does not permit method signatures that are overloaded based on return type.)
We will obtain a lengths value which is an array of 32-bit integers, where the array elements contain the values 10 and 5, as expected.