有没有办法用引号将选定的文本块包装起来?在Visual Studio中,我没有找到扩展或插件,我只是在寻找一种简单的方法来做。有没有添加该功能的方法?
最佳答案
在没有ReSharper的情况下,Visual Studio中也提供了“环绕”选项。它不包含使用引号引起来的选项。但是可以使用自定义包装程序扩展代码片段。也用双引号引起来。要做到这一点:
单击File
,然后单击New
,然后选择文件类型为XML
。
在File
菜单上,单击Save
。
在Save as
框中,选择All Files (*.*)
。
在File name
框中,输入带有.snippet
文件扩展名的文件名。
单击Save
。
将此代码添加到文件中。
码
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>doubleQuotes</Title>
<Author>Microsoft Corporation</Author>
<Shortcut>"</Shortcut>
<Description>Wrap in double quotes</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>selected</ID>
<ToolTip>content</ToolTip>
<Default>content</Default>
</Literal>
</Declarations>
<Code Language="CSharp">"$selected$"</Code>
</Snippet>
</CodeSnippet>
保存文件。
打开
Tools
-> Code Snippets Manager
。在“语言”部分中,选择“ Visual C#”。
单击
Import
并浏览到您刚刚创建的代码段。选中
My Code Snippets
,然后单击Finish
,然后单击OK
。要使用它:选择文本->右键单击->选择“环绕...”->我的代码段-> doubleQoutes
或者:选择文本->按Ctrl + K,S->我的代码段-> doubleQoutes
我从this answer那里得到了这个解决方案的想法,作者展示了如何在自定义html标签中包装代码。
关于visual-studio - Visual Studio用引号将选择换行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757631/