---
title: "Attributes"
description: "Learn how to define and use Slice attributes."
url: https://docs.icerpc.dev/slice/language-guide/attributes
docs_index: https://docs.icerpc.dev/llms.txt
---

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

# Attributes

Learn how to define and use Slice attributes.

## Customize your definitions

A Slice attribute allows you to customize some aspect of your Slice definitions without changing the contract with the peer.

For example, you can map a Slice struct to a read-only C# record struct with the `[cs::readonly]` attribute. The addition of the `readonly` keyword to your C# struct has no effect whatsoever on the data transmitted over the wire.

Adding an attribute to (or removing an attribute from) the Slice definitions of your client application has no effect on an unmodified server application, and vice-versa.

An attribute is enclosed in square brackets just before the construct it applies to. For example:

```slice
[cs::readonly] // a struct attribute
compact struct FooFighter {
    sighting: Coordinates
}

[deprecated("Use Bar instead")] // an interface attribute
interface Foo {
    [oneway] doIt() // an operation attribute
}
```

You can also define a file-level attribute with double square brackets. A file-level attribute is a shortcut to apply this attribute to all definitions in the file that accept this attribute. Among the attributes described on this page, only `allow` can be used as a file-level attribute. For example:

```slice

// The Slice compiler won't emit a warning when a Slice definition
// in this file references a deprecated type.
[[allow(Deprecated)]]

module SampleModule
...
```

## Shared attributes

The following attributes are available in all language mappings:

| Attribute | Applies to | Description |
| --- | --- | --- |
| [`allow`](#allow-attribute) | Interfaces, operations, parameters, user-defined types, fields, enumerators, variants | Suppress warnings during compilation. |
| [`compress`](https://docs.icerpc.dev/slice/language-guide/operation.md#compress-attribute) | Operations | Request compression from the local compressor interceptor or middleware. |
| [`deprecated`](#deprecated-attribute) | Interfaces, operations, user-defined types, fields, enumerators, variants | Mark as deprecated. |
| [`oneway`](https://docs.icerpc.dev/slice/language-guide/operation.md#oneway-attribute) | Operations | Create one-way requests for this operation (client-side only). |

### allow attribute

The allow attribute tells the Slice compiler to not emit warnings in situations where it would normally emit warnings. It accepts one or more of the following arguments:

| Argument | Description |
| --- | --- |
| All | Do not emit any warning that can be suppressed. |
| BrokenDocLink | Do not emit a warning when a doc comment link references an unknown Slice construct. |
| Deprecated | Do not emit a warning when referencing a deprecated type. |
| IncorrectDocComment | Do not emit a warning for a doc comment that is syntactically correct but contains a logic error. |
| MalformedDocComment | Do not emit a warning for doc comments that are syntactically incorrect (as per the doc comment syntax). |

`allow` can be specified as a regular attribute and as a file-level attribute. For example:

```slice
[deprecated("Use Associate instead.")]
compact struct Employee {
    name: string
    phoneNumber: string
}

interface CompanyDirectory {
    [allow(Deprecated)]
    [deprecated("Call lookupAssociate instead.")]
    lookupEmployee(name: string) -> Employee

    lookupAssociate(name: string) -> Associate
}
```

### deprecated attribute

The deprecated attribute marks a Slice definition as deprecated, and accepts an optional string argument. It has two separate purposes:

- make the Slice compiler emit a warning when some other Slice definition references a deprecated type
- when possible, generate a comparable deprecated attribute on the mapped construct

See [allow attribute](#allow-attribute) above for an example.

## C# attributes

The following attributes are specific to the C# mapping. They all start with the `cs::` prefix.

| Attribute | Applies to | Description |
| --- | --- | --- |
| [`cs::attribute`](https://docs.icerpc.dev/slice/language-guide/enum-types.md#cs::attribute-attribute) | Basic enums, enumerators, and fields | Add the specified C# attribute to the mapped C# enum, enumerator, or field. |
| [`cs::encodedReturn`](https://docs.icerpc.dev/slice/language-guide/operation.md#cs::encodedreturn-attribute) | Operations | Return an already encoded return value (server-side only). |
| [`cs::identifier`](#cs::identifier-attribute) | Modules, interfaces, operations, parameters, user-defined types, fields, enumerators, and variants | Change the name of the mapped C# identifier. |
| [`cs::public`](#cs::public-attribute) | Structs, enums, and interfaces | Map to a public C# type instead of an internal C# type. |
| [`cs::readonly`](https://docs.icerpc.dev/slice/language-guide/struct-types.md#cs::readonly-attribute) | Structs and struct fields | Map to a readonly C# struct, or map a field to an init-only property. |
| `cs::type` | [Custom types](https://docs.icerpc.dev/slice/language-guide/custom-types.md#c#-mapping), [sequences](https://docs.icerpc.dev/slice/language-guide/sequence-types.md#cs::type-attribute), and [dictionaries](https://docs.icerpc.dev/slice/language-guide/dictionary-types.md#cs::type-attribute) | Specify the mapped C# type. |

### cs::identifier attribute

The `cs::identifier` attribute specifies the exact mapped C# identifier you want as its argument. The C# code generator does not adjust the case of this identifier, but adds prefixes and suffixes as needed.

For example:

```slice
[cs::identifier("RemoteEnumerator")]
interface Enumerator {
    ...
}
```

```csharp
internal partial interface IRemoteEnumerator
{
    ...
}

internal readonly partial
record struct RemoteEnumeratorProxy :
    IRemoteEnumerator,
    ISliceProxy
{
    ...
}

internal partial interface IRemoteEnumeratorService
{
    ...
}
```

### cs::public attribute

The `cs::public` attribute maps a Slice struct, enum, or interface to one or more public C# types. It does not accept any argument.
