简体   繁体   English

以编程方式折叠来自 Visual Studio 扩展的源代码块

[英]Programmatically collapse source code blocks from a Visual Studio extension

I've written a VS extension which modifies C# source files.我写了一个修改 C# 源文件的 VS 扩展。 The extension applies changes to the source code file which is currently open and visible in the IDE. One aspect of the extension is to insert #region and #endregion directives surrounding the inserted source lines.该扩展将更改应用于当前在 IDE 中打开和可见的源代码文件。该扩展的一个方面是在插入的源代码行周围插入#region 和#endregion 指令。 What I'd like to do from the extension is collapse that region of code in the visible editor window.我想从扩展中做的是在可见编辑器 window 中折叠该代码区域。

I've been searching around for days, and can't find any previous examples of how this can be done.我已经搜索了好几天,但找不到任何以前的例子来说明如何做到这一点。

Any guidance would be greatly appreciated.任何指导将不胜感激。

You can import Microsoft.VisualStudio.Text.Outlining.IOutliningManagerService, call GetOutliningManager and then use TryCollapse.您可以导入 Microsoft.VisualStudio.Text.Outlining.IOutliningManagerService,调用 GetOutliningManager,然后使用 TryCollapse。

https://learn.microsoft.com/en-us/do.net/api/microsoft.visualstudio.text.outlining.ioutliningmanager.trycollapse?view=visualstudiosdk-2022 https://learn.microsoft.com/en-us/do.net/api/microsoft.visualstudio.text.outlining.ioutliningmanager.trycollapse?view=visualstudiosdk-2022

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Visual Studio扩展访问文件的源代码 - How to access source code of a file from a Visual Studio Extension 我可以在Visual Studio 2012中以编程方式折叠/展开某个名称的所有预处理器块吗? - Can I programmatically collapse/expand all preprocessor blocks of a certain name in Visual Studio 2012? 折叠Visual Studio中的所有非活动预处理程序块 - Collapse all inactive preprocessor blocks in Visual Studio Visual Studio:折叠所选代码 - Visual Studio: Collapse selected Code 我可以在Visual Studio 2010中折叠foreach,using和其他c#代码块吗? - Can I collapse foreach, using and other c# code blocks in Visual Studio 2010? Visual Studio从源代码构建应用程序 - visual studio build application from the source code Visual Studio 中代码块中的编译器标志是否有类似物? - Is there an analog to Compiler Flags from Code Blocks in Visual Studio? 如何折叠所有不会在Visual Studio中编译的#ifdef块? - How to collapse all blocks of #ifdefs that will not be compiled in Visual Studio? 如何从扩展代码中获取 Visual Studio 扩展版本 - How ot get Visual studio extension version from the extension code 从Visual Studio扩展中找出ProjectItem的源控件状态 - Find out the source control state of a ProjectItem from a Visual Studio extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM