VS 2010-复制类/接口的完整类型名称的简便方法? [英] VS 2010 - easy way to copy full type name of a class/interface?

查看:191
本文介绍了VS 2010-复制类/接口的完整类型名称的简便方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以复制类/接口/等的全类型名称.在Visual Studio中到剪贴板?特别是,我需要它们用于温莎城堡的配置,并且很想弄清楚如何轻松地做到这一点. (示例:在代码编辑器中突出显示IInterface,最后在剪贴板上显示My.Full.Namespace.Is.Here.IInterface.)

Is there a way to copy the full type name of a class/interface/etc. in Visual Studio to the clipboard? In particular, I need them for Castle Windsor configuration and would love to figure out how to do this effortlessly. (Example: highlight IInterface in the code editor and end up with My.Full.Namespace.Is.Here.IInterface on the clipboard.)

VS将完整类型名称放在左上角的只读组合框中(对于复制目的完全没有用);有人知道吗?

VS puts the full type name in a read-only combobox in the upper left (which is utterly useless for copying purposes); does anyone know a way?

(如果可以使用ReSharper,我可以使用ReSharper.)

(I have ReSharper, if there's a way to do it using that.)

推荐答案

这是一个宏,它可以帮助您继续前进.错误处理非常糟糕,但是我再也无法忍受了,我绝对讨厌VB:)

Here's a macro which does which should get you going. The error handling is abysmal but I couldn't muster more, I absolutely hate VB :)

还请注意,它仅捕获类类型名或接口类型名,您可以在光标位于类或接口定义内的任何位置运行它.它将捕获类/接口范围的名称.

Also note that it only captures a class type name or interface type name, you can run it where ever you want while your cursor is inside a class or interface definition. It will capture the name of the class/interface scope.

由于它是Windows窗体组件,因此需要在STAThread中运行,因此它在线程中运行Clipboard调用.

It runs the Clipboard call in a thread, because it's a Windows Forms component and they need to run in a STAThread.

它将完整的类型名复制到剪贴板.

It copies the full typename to the clipboard.

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

这篇关于VS 2010-复制类/接口的完整类型名称的简便方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆