diff --git a/src/DotNext/Buffers/ByteBuffer.cs b/src/DotNext/Buffers/ByteBuffer.cs index 35745c34a..d3323c8a7 100644 --- a/src/DotNext/Buffers/ByteBuffer.cs +++ b/src/DotNext/Buffers/ByteBuffer.cs @@ -42,7 +42,7 @@ public static int WriteLittleEndian(this IBufferWriter writer, T value) for (var destination = writer.GetSpan(); !value.TryWriteLittleEndian(destination, out length); destination = writer.GetSpan(length)) { length = destination.Length; - length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(); + length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(length); @@ -64,7 +64,7 @@ public static int WriteBigEndian(this IBufferWriter writer, T value) for (var destination = writer.GetSpan(); !value.TryWriteBigEndian(destination, out length); destination = writer.GetSpan(length)) { length = destination.Length; - length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(); + length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(length); @@ -84,7 +84,7 @@ public static int Write(this IBufferWriter writer, in BigInteger value, bo { var buffer = writer.GetSpan(value.GetByteCount(isUnsigned)); if (!value.TryWriteBytes(buffer, out var bytesWritten, isUnsigned, isBigEndian)) - throw new InsufficientMemoryException(); + throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); writer.Advance(bytesWritten); return bytesWritten; @@ -108,7 +108,7 @@ public static int Format(this IBufferWriter writer, T value, ReadOnlySp for (int sizeHint; !value.TryFormat(buffer, out bytesWritten, format, provider); buffer = writer.GetSpan(sizeHint)) { sizeHint = buffer.Length; - sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(); + sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(bytesWritten); @@ -143,7 +143,7 @@ public static int WriteLittleEndian(this ref BufferWriterSlim writer, T for (var destination = writer.InternalGetSpan(sizeHint: 0); !value.TryWriteLittleEndian(destination, out length); destination = writer.InternalGetSpan(length)) { length = destination.Length; - length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(); + length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(length); @@ -165,7 +165,7 @@ public static int WriteBigEndian(this ref BufferWriterSlim writer, T va for (var destination = writer.InternalGetSpan(sizeHint: 0); !value.TryWriteBigEndian(destination, out length); destination = writer.InternalGetSpan(length)) { length = destination.Length; - length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(); + length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(length); @@ -185,7 +185,7 @@ public static int Write(this ref BufferWriterSlim writer, in BigInteger va { var buffer = writer.InternalGetSpan(value.GetByteCount(isUnsigned)); if (!value.TryWriteBytes(buffer, out var bytesWritten, isUnsigned, isBigEndian)) - throw new InsufficientMemoryException(); + throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); writer.Advance(bytesWritten); return bytesWritten; @@ -209,7 +209,7 @@ public static int Format(this ref BufferWriterSlim writer, T value, Rea for (int sizeHint; !value.TryFormat(buffer, out bytesWritten, format, provider); buffer = writer.InternalGetSpan(sizeHint)) { sizeHint = buffer.Length; - sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(); + sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); } writer.Advance(bytesWritten); @@ -258,7 +258,7 @@ public static int WriteLittleEndian(this ref SpanWriter writer, T value where T : notnull, IBinaryInteger { if (!value.TryWriteLittleEndian(writer.RemainingSpan, out var bytesWritten)) - throw new InsufficientMemoryException(); + throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); writer.Advance(bytesWritten); return bytesWritten; @@ -276,7 +276,7 @@ public static int WriteBigEndian(this ref SpanWriter writer, T value) where T : notnull, IBinaryInteger { if (!value.TryWriteBigEndian(writer.RemainingSpan, out var bytesWritten)) - throw new InsufficientMemoryException(); + throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory); writer.Advance(bytesWritten); return bytesWritten; diff --git a/src/DotNext/Buffers/CharBuffer.cs b/src/DotNext/Buffers/CharBuffer.cs index b12b1484f..41e66cc64 100644 --- a/src/DotNext/Buffers/CharBuffer.cs +++ b/src/DotNext/Buffers/CharBuffer.cs @@ -65,7 +65,7 @@ public static int Format(this IBufferWriter writer, CompositeFormat format const int maxBufferSize = int.MaxValue / 2; int bufferSize; - for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException()) + for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory)) { var buffer = writer.GetSpan(bufferSize); if (buffer.TryWrite(provider, format, out bufferSize, args)) @@ -203,7 +203,7 @@ public static int Format(this ref BufferWriterSlim writer, CompositeFormat const int maxBufferSize = int.MaxValue / 2; int bufferSize; - for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException()) + for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory)) { var buffer = writer.InternalGetSpan(bufferSize); if (buffer.TryWrite(provider, format, out bufferSize, args))