BufferExtensions

Namespace: SnowBank.Buffers · class

Helper methods for working with buffers

Methods

TryGetSpan

static bool TryGetSpan<T>(IEnumerable<T> items, out ReadOnlySpan<T> span)

Attempts to extract the contents of this sequence as a ReadOnlySpan

  • items — Source sequence.
  • span — Receives a view of the content of the sequence if it is supported; otherwise, the default value.

Returns: true it was possible to extract the content of the buffer and expose it as a read-only span; otherwise, false.

The following types are currently recognized: T[], List, ImmutableArray

If items is null, the empty span will be returned.

This method does NOT guarantee that the content of the returned span will be stable in time (for example List if the internal buffer is expanded), so the caller should consume the result immediately, or have a way to guarantee that the source will not be modified.