Access current code pane in Visual Studio Extension

穿精又带淫゛_ 提交于 2020-12-29 05:26:26

问题


Im writing a visual studio (2010) extension with a right click menu whilst in a code view. I want to be able to examine the current code from my menu item event handler but havent been able to find somewhere in the object model to do this.

How do i access the code in the current window in a visual studio extension?

EDIT

Heres the code i used to get the current document text

 DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE ;
 TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;

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

回答1:


You may be looking for

Document doc = DTE.ActiveDocument;
TextDocument txt = doc.Object() as TextDocument;

You should then be able to edit work with the TextDocument as needed.



来源:https://stackoverflow.com/questions/9041848/access-current-code-pane-in-visual-studio-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!