Is it possible to map C# object
type in Slice?
#3214
-
I plan to expose a backend written in C# using ICE. Part of the planed API would be: bool SetParam(string name, object value)
object GetParam(string name) How to map the C# API to Slice? A param can be variety of types. In protobuf, there is a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If your focus is C#, you may want to check out IceRPC. In Ice 3.7 and prior releases, we support "object serialization" in C#, which allows you to use C# serialization to marshal any C# object into a sequence of bytes. See: However, I would recommend against using this feature because:
In Ice - Slice, you can model "any" Slice type using the Value keyword - the base class for all Slice classes. You could convert your C# API into: bool SetParam(string name, Value v);
Value GetParam(string name); And then define a number of Slice classes that hold the various types you want to get/set with Get/SetParam: class StringValue { string v; } // holds a string
class ColorValue { Color v; } // holds a Color enumerator
... New Slice provides a more elegant and efficient solution: enum with fields enum Shape {
Circle(radius: uint32)
Rectangle(width: uint32, length: uint32)
Dot
} It's nicer than Protobuf's Any type, and it could be better suited for your use-case. |
Beta Was this translation helpful? Give feedback.
Yes, IceRPC with Slice1 and the ice protocol interoperates with Ice except for a few uncommon situations (you use compression with Ice, or you use batch requests with Ice). For most applications, there is no interop issue.
However, IceRPC C# requires a recent .NET (.NET 8.0 or 9.0). It won't work with .NET Framework 4.8.