-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom type mapping (cs::type attribute) #674
Comments
If I understand this correctly the extension methods are placed in the namespace where the typealias is defined? |
I think we currently don't distinguish |
This is correct. For example:
After parsing, this will become:
There is currently no way to tell whether a type was originally from an alias or not. |
so should we go with the solution proposed in icerpc/slicec#73 (comment) and make |
yes |
Fixed by #782. |
You define a type in Slice but the C# mapping from slicec-cs is not quite what you want. This is a proposal to address this issue and give you complete freedom to map any Slice-defined type to the type of your choice.
For example:
we define Slice struct EndpointData and want to map it to record class Endpoint in C#
We already have the code that encodes an Endpoint into an EndpointData and decodes an EndpointData into an Endpoint. We just want to "plug it in" slicec-cs to get Endpoint instead of EndpointData for mapped parameters, fields etc.
we define Fields as:
It's mapped to
IDictionary<int, IList<byte>>
, but we'd rather map it toImmutableDictionary<int, ReadOnlyMemory<byte>>
.Proposed solution
The cs::type attribute is a typealias attribute that specifies the mapped type. The provided string is then generated verbatim by the Slice compiler.
For example:
then all parameters, data members etc of type (IceRpc::Slice::Internal::)Endpoint in Slice definitions are mapped to IceRpc.Endpoint in C#.
The Slice compiler then uses:
IceRpc.Slice.Internal.EndpointDecoderExtensions.DecodeEndpoint
to decode an Endpoint from a SliceDecoder andIceRpc.Slice.Internal.EndpointEncoderExtensions.EncodeEndpoint
to encode an endpoint.More generally, for
The Slice compiler uses
M.ADecoderExtensions.DecodeA
to decode an A andM.AEncoderExtensions.EncodeA
to encode an A.For Fields:
and the encoder/decoder methods are IceRpc.FieldsDecoderExtensions.DecodeFields and IceRpc.FieldsEncoderExtensionsEncodeFields.
This proposal relies on typealias (obviously), and with proposal, the specified custom mapped type is used all the time:
The text was updated successfully, but these errors were encountered: