public byte[] GetSourceRange(int startLine, int startColumn, int endLine, int endColumn) { byte[] data; int count; unmanagedDocument.GetSourceRange(startLine, startColumn, endLine, endColumn, 0, out count, null); data = new byte[count]; unmanagedDocument.GetSourceRange(startLine, startColumn, endLine, endColumn, count, out count, data); return(data); }
public byte[] GetSourceRange(int startLine, int startColumn, int endLine, int endColumn) { uint bufSize; document.GetSourceRange((uint)startLine, (uint)startColumn, (uint)endLine, (uint)endColumn, 0, out bufSize, null); var buffer = new byte[bufSize]; document.GetSourceRange((uint)startLine, (uint)startColumn, (uint)endLine, (uint)endColumn, (uint)buffer.Length, out bufSize, buffer); return(buffer); }
public byte[] GetSourceRange(int startLine, int startColumn, int endLine, int endColumn) { int size; HRESULT.ThrowOnFailure(_unmanaged.GetSourceRange(startLine, startColumn, endLine, endColumn, 0, out size, null)); byte[] data = new byte[size]; HRESULT.ThrowOnFailure(_unmanaged.GetSourceRange(startLine, startColumn, endLine, endColumn, data.Length, out size, data)); return(data); }
/// <summary> /// Returns the embedded source for specified document. /// </summary> /// <param name="document">The document to read source of.</param> /// <returns> /// default(<see cref="ArraySegment{T}"/>) if the document doesn't have embedded source, /// otherwise byte array segment containing the source. /// </returns> public static ArraySegment <byte> GetEmbeddedSource(this ISymUnmanagedDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } Marshal.ThrowExceptionForHR(document.GetSourceLength(out int length)); if (length == 0) { return(default(ArraySegment <byte>)); } if (length < sizeof(int)) { throw new InvalidDataException(); } var blob = new byte[length]; Marshal.ThrowExceptionForHR(document.GetSourceRange(0, 0, int.MaxValue, int.MaxValue, length, out int bytesRead, blob)); if (bytesRead < sizeof(int) || bytesRead > blob.Length) { throw new InvalidDataException(); } int uncompressedLength = BitConverter.ToInt32(blob, 0); if (uncompressedLength == 0) { return(new ArraySegment <byte>(blob, sizeof(int), bytesRead - sizeof(int))); } var uncompressedBytes = new byte[uncompressedLength]; var compressed = new MemoryStream(blob, sizeof(int), bytesRead - sizeof(int)); using (var decompressor = new DeflateStream(compressed, CompressionMode.Decompress)) { int position = 0; while (true) { int bytesDecompressed = decompressor.Read(uncompressedBytes, position, uncompressedBytes.Length - position); if (bytesDecompressed == 0) { break; } position += bytesDecompressed; } if (position != uncompressedBytes.Length || decompressor.ReadByte() != -1) { throw new InvalidDataException(); } return(new ArraySegment <byte>(uncompressedBytes)); } }
public static byte[] GetRawEmbeddedSource(this ISymUnmanagedDocument document) { Marshal.ThrowExceptionForHR(document.GetSourceLength(out int length)); if (length == 0) { return(null); } if (length < sizeof(int)) { throw new InvalidDataException(); } var sourceBlob = new byte[length]; Marshal.ThrowExceptionForHR(document.GetSourceRange(0, 0, int.MaxValue, int.MaxValue, length, out int bytesRead, sourceBlob)); if (bytesRead < sizeof(int) || bytesRead > sourceBlob.Length) { throw new InvalidDataException(); } return(sourceBlob); }