visual-studio-2010 - VS 2010 - 复制类/接口(interface)的完整类型名称的简单方法?

标签 visual-studio-2010 ioc-container

有没有办法复制类/接口(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/

相关文章:

c# - 如何使 Windows 窗体中的多个控件随窗口自动调整大小?

c# - 如何将 WinForm 用户控件添加到 WPF 中以便我可以在 xaml.cs 文件中引用它

c# - 类型 : "Namespace.type" not found 的构造函数

c# - 接口(interface)的调度程序实现的 Ninject 绑定(bind)

dependency-injection - 使用 Ninject 并绑定(bind)默认实现,同时避免可怕的 Service Locator 反模式

c# - IoC 容器中一次性注入(inject)类

c++ - 如何在Visual Studio中的MFC中的ListControl中显示选中的文件名?

c# - Visual Studio 2010 只有 x86 构建选项?

visual-studio-2010 - 如何让调试器在 visual studio 中显示未使用的变量?

ninject - 如何迭代 Ninject StandardKernel 的已配置绑定(bind)以进行调试?