---
title: "Slice Metadata Directives"
url: https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives
language: csharp
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Slice Metadata Directives

Programming language: C#. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/cpp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/swift.md).

## Overview

A metadata directive gives the Slice compilers an instruction about a Slice definition or a Slice file. Most directives customize the code generated for one language mapping, and start with the prefix of this mapping, such as `java:`:

```slice
["java:type:java.util.LinkedList<Integer>"] sequence<int> IntSeq;
```

The general directives have no prefix. For example, `format` selects how Ice marshals class instances, and `deprecated` marks a definition as deprecated.

You place directives in square brackets before the definition they apply to, separated by commas or in consecutive lists, as in `["amd"]["deprecated"]`:

```slice
["amd", "deprecated"]
interface Greeter
{
    string greet(string name);
}
```

A file directive applies to a whole Slice file. You place it in double square brackets before any definition in this file; it can follow `#include` directives:

```slice
[["cpp:dll-export:WIDGET_API"]]
```

Each directive applies only to certain kinds of definitions, listed in its description below.

## General Metadata Directives

### amd

`["amd"]`. Applies to interfaces and operations.

In C++, C#, and Java, the skeleton provides an asynchronous method for the operation, or for each operation of the interface, instead of a synchronous method. Instead of using this directive, you can also derive your servant class from the asynchronous skeleton; see [Operations](https://docs.zeroc.com/ice/3.8/slice/operations/csharp.md). The other Slice compilers ignore this directive.

### deprecated

`["deprecated"]` or `["deprecated:message"]`. Applies to interfaces, operations, classes, exceptions, structs, sequences, dictionaries, enumerations, enumerators, constants, and fields.

This directive marks a definition as deprecated; see [Deprecating Slice Definitions](https://docs.zeroc.com/ice/3.8/slice/deprecating-slice-definitions.md).

### format

`["format:compact"]` or `["format:sliced"]`. Applies to interfaces and operations.

This directive selects the [encoding format](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slicing-values-and-exceptions/csharp.md) of the class instances marshaled as the arguments or result of an operation: `format:compact` selects the compact format, and `format:sliced` selects the sliced format. On an interface, it applies to all the operations of the interface; on an operation, it overrides the `format` directive of the enclosing interface.

When neither an operation nor its enclosing interface selects a format, the [Ice.Default.SlicedFormat](https://docs.zeroc.com/ice/3.8/property-reference/ice-default-properties/csharp.md#ice.default.slicedformat) property selects it.

> **Note**
>
> This directive does not apply to user exceptions: Ice always marshals them in the sliced format.

### marshaled-result

`["marshaled-result"]`. Applies to interfaces and operations.

This directive lets a servant marshal the results of an operation as soon as it computes them, typically while it holds the lock that protects the data it returns. The mapped skeleton method returns a “marshaled result” struct or class whose constructor marshals the return value and out parameters immediately.

On an interface, this directive applies to every operation that the interface defines. The Slice compiler changes the mapping of an operation only when its return type or one of its out parameters is a class, struct, sequence, or dictionary. This directive affects the server-side mapping in C++, C#, and Java, and has no effect on the client-side mapping.

For example:

```slice
module M
{
    sequence<int> IntSeq;
    sequence<IntSeq> IntIntSeq;
    sequence<string> StringSeq;

    class Grid
    {
        StringSeq xLabels;
        StringSeq yLabels;
        IntIntSeq values;
    }

    interface GridIntf
    {
        // We want to marshal the returned Grid object within a lock,
        // and return a consistent object not affected by concurrent calls to
        // clearValues.
        ["marshaled-result"]
        ["cs:identifier:GetGrid"]
        Grid getGrid();

        void clearValues();
    }
}
```

The mapped skeleton method for `getGrid` is:

```csharp
GridIntf_GetGridMarshaledResult GetGrid(Ice.Current current);
```

where `GridIntf_GetGridMarshaledResult` is a generated record struct with a constructor that accepts a parameter for the return value, followed by `Current`:

```csharp
// Generated server-side code
public readonly record struct GridIntf_GetGridMarshaledResult : Ice.MarshaledResult
{
    // Marshals returnValue immediately.
    public GridIntf_GetGridMarshaledResult(Grid? ret, Ice.Current current)
    {
        ...
    }
    ...
}
```

A typical implementation of the `getGrid` operation in your servant would be:

```csharp
public override GridIntf_GetGridMarshaledResult GetGrid(Ice.Current current)
{
    lock (_mutex)
    {
       // marshal _grid field within synchronization
       return new GridIntf_GetGridMarshaledResult(_grid, current);
    }
}
```

> **Warning**
>
> A marshaled-result instance is specific to a request. Do not cache a marshaled result and return it for another request.

### oneway

`["oneway"]`. Applies to operations.

This directive restricts an operation to oneway invocations. The operation cannot have a return type, out parameters, or an exception specification.

### suppress-warning

`[["suppress-warning"]]` or `[["suppress-warning:category, ..."]]`. Applies to a Slice file.

This directive suppresses Slice compiler warnings for all the definitions in the Slice file. Without a category, it suppresses all warnings; with one or more categories, it suppresses only the warnings in these categories:

| **Category** | **Description** |
| --- | --- |
| `all` | Suppress all Slice compiler warnings. Equivalent to `[["suppress-warning"]]`. |
| `deprecated` | Suppress warnings related to deprecated features. |
| `invalid-comment` | Suppress warnings related to invalid doc comments. |

## Language-Specific Metadata Directives

C# metadata directives use the `cs` prefix.

### cs:attribute

`["cs:attribute:attribute"]`. Applies to enumerations, enumerators, constants, and fields.

This directive adds the C# attribute `attribute` to the generated code. For example, `["cs:attribute:System.Flags"]` on an enumeration adds `[System.Flags]` to the mapped C# enum.

### cs:class

`["cs:class"]`. Applies to structs.

This directive maps the Slice struct to a C# class instead of a C# struct.

### cs:generic

`["cs:generic:type"]`. Applies to sequences and dictionaries.

On a [sequence](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/csharp.md), `type` is `List`, `LinkedList`, `Queue`, `Stack`, or a custom collection type; `LinkedList`, `Queue`, and `Stack` are not supported on a sequence of classes. On a [dictionary](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/csharp.md), `type` is `SortedDictionary` or `SortedList`.

### cs:identifier

`["cs:identifier:name"]`. Applies to any definition, parameter, or field.

The generated C# code uses `name` instead of the Slice identifier. For example:

```slice
interface Greeter
{
    ["cs:identifier:Greet"]
    string greet(string name);
}
```

The operation `greet` maps to the methods `Greet` and `GreetAsync` in C#, instead of `greet` and `greetAsync`.

### cs:internal

`["cs:internal"]`. Applies to interfaces, classes, exceptions, structs, sequences, dictionaries, enumerations, and constants.

This directive makes the generated C# declarations `internal` instead of `public`.

### cs:namespace

`["cs:namespace:enclosing-namespace"]`. Applies to top-level modules.

This deprecated directive nests the C# namespace of the module in `enclosing-namespace`: with `["cs:namespace:Acme"]` on `module Demo`, the generated code is in the namespace `Acme.Demo`. Use `cs:identifier` instead.

### cs:property

`["cs:property"]`. Applies to structs, classes, and exceptions.

This directive maps the Slice fields to C# properties instead of C# [fields](https://docs.zeroc.com/ice/3.8/slice/fields/csharp.md).

### cs:readonly

`["cs:readonly"]`. Applies to structs.

When the Slice struct maps to a C# record struct, the mapped record struct is marked `readonly`.

When the Slice struct maps to a C# record class, the fields of this class are mapped to readonly C# fields or get-only properties (see `cs:property`), except for fields with a Slice class type that are mapped as usual (read-write fields or get-set properties).
