# IDehydrationContext Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idehydrationcontext/)

## AddBytes(string, ReadOnlySpan&lt;byte&gt;) {#addbytes-string-system-readonlyspan-byte-2d4f0afb}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idehydrationcontext/methods/addbytes-string-system-readonlyspan-byte-2d4f0afb/)

```csharp
public abstract void AddBytes(string key, ReadOnlySpan<byte> value)
```

Adds a sequence of bytes to the dehydration context, associating the sequence with the provided key.

### Parameters

- `key` (`string`): The key.
- `value` (`ReadOnlySpan<byte>`): The value.

## AddBytes(string, Action&lt;T, IBufferWriter&lt;byte&gt;&gt;, T) {#addbytes-1-string-system-action-t-system-buffers-ibufferwriter-byte-t-fe82d303}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idehydrationcontext/methods/addbytes-1-string-system-action-t-system-buffers-ibufferwriter-byte-t-fe82d303/)

```csharp
public abstract void AddBytes<T>(string key, Action<T, IBufferWriter<byte>> valueWriter, T value)
```

Adds a sequence of bytes to the dehydration context, associating the sequence with the provided key.

### Parameters

- `key` (`string`): The key.
- `valueWriter` (`Action<T, IBufferWriter<byte>>`): A delegate used to write the provided value to the context.
- `value` (`T`): The value to provide to `valueWriter`.

## TryAddValue(string, T?) {#tryaddvalue-1-string-t-nullable-9d122a27}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.runtime.idehydrationcontext/methods/tryaddvalue-1-string-t-nullable-9d122a27/)

```csharp
public abstract bool TryAddValue<T>(string key, T? value)
```

Attempts to a value to the dehydration context, associated with the provided key, serializing it using [Serializer](/orleans/docs/api/csharp/microsoft.orleans.serialization/orleans.serialization.serializer/). If a serializer is found for the value, and the key has not already been added, then the value is added and the method returns `true`. If no serializer exists or the key has already been added, then the value is not added and the method returns `false`.

### Parameters

- `key` (`string`): The key.
- `value` (`T?`): The value to add.
