[英]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.