Composite type
A struct is a user-defined type that holds a list of fields. For example:
C# mapping
A Slice struct maps to a public C# record struct with the same name. For example:
The mapped C# record struct provides a primary constructor with parameters for all its fields, and also a decoding constructor that constructs a new instance by decoding its fields from a SliceDecoder
. The generated Encode
method encodes the struct fields with a SliceEncoder
.
cs::readonly attribute
You can map a Slice struct to a readonly C# struct with the cs::readonly
attribute. This attribute does not accept any argument. For example:
slice
[cs::readonly]compact struct Point { x: int32, y: int32 }
C#
public readonly partial record struct Point{ public int X { get; init; } public int Y { get; init; }
...}
You can also apply cs::readonly
to a struct field to map this field to a get-init property.