Table of Contents

Class UnsafeExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides extensions for unsafe context.

public static class UnsafeExtensions
Inheritance
UnsafeExtensions
Inherited Members

Methods

AsBytes<TSource>(ReadOnlySpan<TSource>)

Converts the given span into a span of bytes.

public static ReadOnlySpan<byte> AsBytes<TSource>(this ReadOnlySpan<TSource> source) where TSource : struct

Parameters

source ReadOnlySpan<TSource>

Returns

ReadOnlySpan<byte>

Type Parameters

TSource

Remarks

The actual byte length of the span is preserved, the original span is unaffected and the result reinterprets the same content as a span of bytes.

GetBytes<T>(ref T)

Gets a ReadOnlySpan<T> containing the bytes of the provided value.

public static ReadOnlySpan<byte> GetBytes<T>(this ref T value) where T : unmanaged

Parameters

value T

The value whose bytes to get.

Returns

ReadOnlySpan<byte>

The bytes of the value.

Type Parameters

T

The type of the value whose bytes to get.

GetValueFromSpan<T>(Span<byte>)

Gets the value of an unmanaged struct, given a Span<T>.

public static T GetValueFromSpan<T>(this Span<byte> span) where T : unmanaged

Parameters

span Span<byte>

The Span<T> from which to get the bytes of the struct.

Returns

T

Type Parameters

T

The type of the unmanaged struct.