diff --git a/csharp/sbe-dll/DirectBuffer.cs b/csharp/sbe-dll/DirectBuffer.cs index d71783aff1..5f99778924 100644 --- a/csharp/sbe-dll/DirectBuffer.cs +++ b/csharp/sbe-dll/DirectBuffer.cs @@ -120,7 +120,7 @@ public int Capacity { get { return _capacity; } } - + /// /// Check that a given limit is not greater than the capacity of a buffer from a given offset. /// @@ -129,17 +129,22 @@ public void CheckLimit(int limit) { if (limit > _capacity) { - if (bufferOverflow == null) - throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity)); + TryResizeBuffer(limit); + } + } - var newBuffer = bufferOverflow(_capacity, limit); + private void TryResizeBuffer(int limit) + { + if (bufferOverflow == null) + throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity)); - if (newBuffer == null) - throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity)); + var newBuffer = bufferOverflow(_capacity, limit); - Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity); - Wrap(newBuffer); - } + if (newBuffer == null) + throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity)); + + Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity); + Wrap(newBuffer); } ///