Parameters and return values

Learn how Ice parameters and return values are mapped to C#

An in parameter is mapped to a C# parameter with the same name, with name converted to camel case; its type is the mapped C# type.

For example, an Ice parameter string name is mapped to a C# parameter string name.

Out parameters and return values are mapped to tuple elements of the Task or ValueTask return value. The return value (if any) appears before the out parameters in the tuple, and is named ReturnValue.

Consider this example:

ice
interface Example
{
double op(int inP1, string inP2, out bool outP1, out long outP2);
}

The Ice compiler generates the following C# code for this interface:

C#
// Client-side interface
public partial interface IExample
{
Task<(double ReturnValue, bool OutP1, long OutP2)> OpAsync(
int inP1,
string inP2,
IceRpc.Features.IFeatureCollection? features = null,
CancellationToken cancellationToken = default);
}
// Client-side proxy struct
public readonly partial record struct ExampleProxy : IExample, IIceProxy { ... }
// Server-side interface
public partial interface IExampleService
{
ValueTask<(double ReturnValue, bool OutP1, long OutP2)> OpAsync(
int inP1,
string inP2,
IceRpc.Features.IFeatureCollection features,
CancellationToken cancellationToken);
}

The mapping for optional parameters is the same as for required parameters, except each mapped C# type is nullable, where null represents "not set".

Consider the following operation:

ice
optional(1) int execute(optional(2) string parameters, out optional(3) float value);

The corresponding C# client-side method is:

C#
Task<(int? ReturnValue, float? Value)> ExecuteAsync(
string? parameters,
IceRpc.Features.IFeatureCollection? features = null,
CancellationToken cancellationToken = default);

and the corresponding C# server-side method is:

C#
ValueTask<(int? ReturnValue, float? Value)> ExecuteAsync(
string? parameters,
IceRpc.Features.IFeatureCollection features,
CancellationToken cancellationToken);

Was this page helpful?

CookiesYour privacy
This website uses cookies to analyze traffic and improve your experience.
By clicking "Accept," you consent to the use of these cookies. You can learn more about our cookies policy in our Privacy Policy.