# CaseAttribute

Package: [Microsoft.Orleans.Serialization.Abstractions](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/) 10.0.0

[NuGet package](https://www.nuget.org/packages/Microsoft.Orleans.Serialization.Abstractions) | [Source](https://github.com/dotnet/orleans/blob/4e887e9c914a2f2647fb3c81de963511521dd9cb/src/Orleans.Serialization.Abstractions/Annotations.cs#L318)

```csharp
public sealed class CaseAttribute : Attribute
```

Assigns a case identifier to a direct subtype of a `closed` type which has [GenerateSerializerAttribute](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/orleans.generateserializerattribute/) applied.

## Remarks

When the direct subtypes of a closed type have case identifiers, a field declared as the closed type is serialized as a tagged union: the case identifier is encoded in the header of the field holding the case value, so the runtime type of a value is not encoded when it is exactly the case type. Values whose runtime type derives from an unsealed case type are encoded as that case, followed by their runtime type.

Case identifiers are scoped to the closed type and must be unique within it. Every direct subtype of the closed type must have a case identifier. Case identifiers are part of the serialized format, so they must remain stable once data has been serialized. Identifiers 0 through 6 are encoded without additional bytes.

Adding case identifiers changes writers to the tagged-union format. Adopt them on an existing hierarchy using a coordinated deployment of the updated hierarchy to all processes which exchange these values. Readers generated for the updated hierarchy accept both the runtime-type format and the tagged-union format.

A closed type and a union type have the same serialized representation when the union's cases are the closed type's direct subtypes with the same case identifiers (see [CaseIdsAttribute](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/orleans.caseidsattribute/)). A `null` closed-type value is represented as an empty union value. A closed type hierarchy can therefore be replaced by an equivalent union type without changing serialized data. Each case's own representation includes its base type's members, so to remove the closed base from the cases when replacing it with a union, declare the closed base without serialized members and apply [SerializerTransparentAttribute](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/orleans.serializertransparentattribute/) to it.

## Constructors

- [CaseAttribute(uint)](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/orleans.caseattribute/constructors/constructor-uint-f332b302/)

## Properties

- [Id](/orleans/docs/api/csharp/microsoft.orleans.serialization.abstractions/orleans.caseattribute/properties/id-14375f1b/)
