Znav |
---|
next | C-Sharp Specific Metadata Directives |
---|
prev | C-Sharp Mapping for Classes |
---|
|
In addition to serializing Slice types, applications may also need to incorporate foreign types into their Slice definitions. Ice allows you to pass CLR serializable objects directly as operation parameters or as fields of another data type. For example:
Wiki Markup |
---|
{zcode:slice}
["clr:serializable:SomeNamespace.CLRClass"]
sequence<byte> CLRObj;
struct MyStruct {
int i;
CLRObj o;
};
interface Example {
void op(CLRObj o, MyStruct s);
};
{zcode} |
The generated code for MyStruct
contains member i
of type int
and a member o
of type SomeNamespace.CLRClass
:
Wiki Markup |
---|
{zcode:cs}
public partial class MyStruct : _System.ICloneable {
public int i;
SomeNamespace.CLRClass o;
// ...
}
{zcode} |
Similarly, the signature for op
has parameters of type CLRClass
and MyStruct
:
Wiki Markup |
---|
{zcode:cs}
void op(SomeNamespace.CLRClass o, MyStruct s);
{zcode} |
Of course, your client and server code must have an implementation of CLRClass
that sets the Serializable
attribute:
Wiki Markup |
---|
{zcode:cs}
namespace SomeNamespace {
[Serializable]
public class CLRClass {
// ...
}
}
{zcode} |
You can implement this class in any way you see fit — the Ice run time does not place any other requirements on the implementation. However, note that the CLR requires the class to reside in the same assembly for client and server.
See Also
Znav |
---|
next | C-Sharp Specific Metadata Directives |
---|
prev | C-Sharp Mapping for Classes |
---|
|