有没有办法复制类/接口(interface)/等的完整类型名称?在 Visual Studio 中到剪贴板?特别是,我需要它们来配置 CaSTLe Windsor,并且很想弄清楚如何轻松地做到这一点。 (示例:在代码编辑器中突出显示 IInterface,并在剪贴板上以 My.Full.Namespace.Is.Here.IInterface 结尾。)
VS 将完整的类型名称放在左上角的只读组合框中(这对于复制目的毫无用处);有谁知道办法吗?
(我有 ReSharper,如果有办法使用它的话。)
最佳答案
这是一个可以让您继续前进的宏。错误处理很糟糕,但我无法收集更多信息,我绝对讨厌 VB :)
另请注意,它仅捕获类类型名称或接口(interface)类型名称,当光标位于类或接口(interface)定义内时,您可以在任何需要的地方运行它。它将捕获类/接口(interface)范围的名称。
它在线程中运行剪贴板调用,因为它是一个 Windows 窗体组件,它们需要在 STAThread 中运行。
它将完整的类型名称复制到剪贴板。
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module SkurmedelMacros
Public Sub SetClipboard(ByVal x As Object)
System.Windows.Forms.Clipboard.SetText(CStr(x), System.Windows.Forms.TextDataFormat.Text)
End Sub
Public Sub GetTypeName()
Dim solution As Solution = DTE.Solution
Dim activePoint As TextPoint = CType(DTE.ActiveDocument.Selection, TextSelection).ActivePoint
Dim codeElem As CodeElement = _
DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(activePoint, vsCMElement.vsCMElementClass)
If codeElem Is Nothing Then
codeElem = DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(activePoint, vsCMElement.vsCMElementInterface)
End If
Dim ClipBoardThread As System.Threading.Thread = New System.Threading.Thread(AddressOf SetClipboard)
With ClipBoardThread
.ApartmentState = System.Threading.ApartmentState.STA
.IsBackground = True
.Start(codeElem.FullName)
.Join()
End With
ClipBoardThread = Nothing
End Sub
End Module
关于visual-studio-2010 - VS 2010 - 复制类/接口(interface)的完整类型名称的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4971997/