コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Visual Studio 拡張機能作成】開いているテキストドキュメントの文字列をすべて取得する方法

ソースコード

var dte = ServiceProvider.GetService( typeof( _DTE ) ) as _DTE;
if ( dte == null ) return;

var activeDocument = dte.ActiveDocument;
if ( activeDocument == null ) return;
var textDocument = activeDocument.Object() as TextDocument;
if ( textDocument == null ) return;

var text = textDocument
    .CreateEditPoint( textDocument.StartPoint )
    .GetText( textDocument.EndPoint )
;

参考サイト様