NetworkCommsDotNet.Tools.StreamTools.ThreadSafeStream.GetBuffer C# (CSharp) Method

GetBuffer() public method

Attempts to return the buffer associated with the internal stream. In certain circumstances this is more efficient than copying the stream contents into a new buffer using ToArray. If the internal stream is not a memory stream will throw InvalidCastException. If access to the buffer is not allowed will throw an UnauthorizedAccessException.
public GetBuffer ( ) : byte[]
return byte[]
            public byte[] GetBuffer()
            {
#if NETFX_CORE
            throw new  NotImplementedException("This method has not been implemented for Win RT");
#else
                MemoryStream _innerMemoryStream = _innerStream as MemoryStream;
                if (_innerMemoryStream != null)
                    return _innerMemoryStream.GetBuffer();
                else
                    throw new InvalidCastException("Unable to return stream buffer as inner stream is not a MemoryStream.");
#endif
            }