src/Misc/EFTools/DesignXmlCore/Refactoring/PreviewBuffer.cs
/// <summary>
///     Copy file content to the TextLines buffer
/// </summary>
Copy file content to the TextLines buffer
Copy file content to the TextLines buffer
[SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults",
            MessageId =
                "Microsoft.VisualStudio.TextManager.Interop.IVsTextLines.ReplaceLines(System.Int32,System.Int32,System.Int32,System.Int32,System.IntPtr,System.Int32,Microsoft.VisualStudio.TextManager.Interop.TextSpan[])"
            )]
        private static void CopyFileToBuffer(string sourceFilename, IVsTextLines buffer)
        {
            ArgumentValidation.CheckForEmptyString(sourceFilename, "sourceFileName");
            ArgumentValidation.CheckForNullReference(buffer, "buffer");
            var spanDst = GetBufferSpan(buffer);
            var pContent = IntPtr.Zero;
            try
            {
                var content = RdtManager.Instance.ReadFromFile(sourceFilename);
                pContent = Marshal.StringToHGlobalAuto(content);
                buffer.ReplaceLines(
                    spanDst.iStartLine, spanDst.iStartIndex,
                    spanDst.iEndLine, spanDst.iEndIndex, pContent, content.Length, new[] { new TextSpan() });
            }
            finally
            {
                if (pContent != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pContent);
                }
            }
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] private static void CopyFileToBuffer ( string sourceFilename , IVsTextLines buffer ) { ArgumentValidation . CheckForEmptyString ( sourceFilename , " " ) ; ArgumentValidation . CheckForNullReference ( buffer , " " ) ; var spanDst = GetBufferSpan ( buffer ) ; var pContent = IntPtr . Zero ; try { var content = RdtManager . Instance . ReadFromFile ( sourceFilename ) ; pContent = Marshal . StringToHGlobalAuto ( content ) ; buffer . ReplaceLines ( spanDst . iStartLine , spanDst . iStartIndex , spanDst . iEndLine , spanDst . iEndIndex , pContent , content . Length , new [ ] { new TextSpan ( ) } ) ; } finally { if ( pContent != IntPtr . Zero ) { Marshal . FreeHGlobal ( pContent ) ; } } }
Copy file content to the TextLines buffer
Copy file content to the TextLines buffer
sourceFilename
string
buffer
IVsTextLines