The slice2cs
compiler supports metadata directives that allow you to inject C# attribute specifications into the generated code. The metadata directive is cs:attribute:
. For example:
{zcode:slice} ["cs:attribute:System.Serializable"] struct Point { double x; double y; }; {zcode} |
This results in the following code being generated for S
:
{zcode:cs} [System.Serializable] public partial struct Point { public double x; public double y; // ... } {zcode} |
You can apply this metadata directive to any Slice construct, such as structure, operation, or parameter definitions.
You can use this directive also at global level. For example:
{zcode:slice} [["cs:attribute:assembly: AssemblyDescription(\"My assembly\")"]] {zcode} |
This results in the following code being inserted after any using
directives and before any definitions:
{zcode:cs} [assembly: AssemblyDescription("My assembly")] {zcode} |