16 readonly Memory<T> _memory;
32 [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 get => _memory.Slice(0, _index);
39 [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 get => _memory.Slice(0, _index).Span;
46 [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 get => _memory.Length;
60 [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 get => _memory.Length - _index;
67 _memory.Slice(0, _index).Span.Clear();
76 ThrowArgumentOutOfRangeExceptionForNegativeCount();
79 if (_index > _memory.Length - count)
81 ThrowArgumentExceptionForAdvancedTooFar();
90 ValidateSizeHint(sizeHint);
92 return _memory.Slice(_index);
98 ValidateSizeHint(sizeHint);
100 return _memory.Slice(_index).Span;
107 [MethodImpl(MethodImplOptions.AggressiveInlining)]
108 void ValidateSizeHint(
int sizeHint)
112 ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
120 ThrowArgumentExceptionForCapacityExceeded();
129 if (typeof(T) == typeof(
char))
131 return _memory.Slice(0, _index).ToString();
135 return $
"IKVM.CoreLib.Buffers.MemoryBufferWriter<{typeof(T)}>[{_index}]";
141 static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
143 throw new ArgumentOutOfRangeException(
"count",
"The count can't be a negative value");
149 static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
151 throw new ArgumentOutOfRangeException(
"sizeHint",
"The size hint can't be a negative value");
157 static void ThrowArgumentExceptionForAdvancedTooFar()
159 throw new ArgumentException(
"The buffer writer has advanced too far");
165 static void ThrowArgumentExceptionForCapacityExceeded()
167 throw new ArgumentException(
"The buffer writer doesn't have enough capacity left");