public static void RequiresInInclusiveRange(int start, int end, int length) { if (!(start >= 0 && start <= end && end >= 0 && end <= length)) { throw new ArgumentOutOfRangeException(); } } }
public static void Write <[Primitive] T>(this Span <byte> slice, T value) where T : struct { Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length); Span <T> castedSlice = slice.Cast <byte, T>(); castedSlice[0] = value; }