从 Visual Studio 加载项访问可用类型列表?

发布于 2024-12-16 12:50:10 字数 1508 浏览 2 评论 0原文

Is there a way to access the types (Classes, Interfaces, etc., and their meta data) that are available inside the loaded projects within a solution in Visual Studio?

To be more specific, I'm attempting to develop a simple Visual Studio Add In to provide "Go To Implementation" functionality:

https://bitbucket.org/jbubriski/go-to-implementation/

I realize that this exists in other productivity Add Ins/Extensions, but I'm making a bare bones one so我 don't have to deal with slow downs, hangs, and crashes from other added "features".

If you look at the source, I'm able to get the currently selected text using a very basic and fragile method. Given the selection, I basically assume that it is an interface, strip off the 'I', and do a Solution-wide search for ProjectItems where the file name ends in "\TypeName.cs “

Is there some internal list of types that Visual Studio maintains for intellisense that I have access to? It would be nice to say:

var vsType = VS.GetLocalType("TypeName")

Then access

vsType.FileName

One step further would be

foreach(var vsType in VS.GetlocalTypes())
{
    if(vsType.Implements.Contains("IInterfaceName"))
    {
        // Found something that implements my interface!
    }
}

Any ideas?

Is there a way to access the types (Classes, Interfaces, etc., and their meta data) that are available inside the loaded projects within a solution in Visual Studio?

To be more specific, I'm attempting to develop a simple Visual Studio Add In to provide "Go To Implementation" functionality:

https://bitbucket.org/jbubriski/go-to-implementation/

I realize that this exists in other productivity Add Ins/Extensions, but I'm making a bare bones one so I don't have to deal with slow downs, hangs, and crashes from other added "features".

If you look at the source, I'm able to get the currently selected text using a very basic and fragile method. Given the selection, I basically assume that it is an interface, strip off the 'I', and do a Solution-wide search for ProjectItems where the file name ends in "\TypeName.cs".

Is there some internal list of types that Visual Studio maintains for intellisense that I have access to? It would be nice to say:

var vsType = VS.GetLocalType("TypeName")

Then access

vsType.FileName

One step further would be

foreach(var vsType in VS.GetlocalTypes())
{
    if(vsType.Implements.Contains("IInterfaceName"))
    {
        // Found something that implements my interface!
    }
}

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书信已泛黄 2024-12-23 12:50:10

不确定本机 VS 插件实现,但如果您使用 DevExpress.CodeRush,转到定义功能应该基于源文件中的当前位置,并执行类似以下操作来检索对声明类型的引用:
((TypeReferenceExpression)CodeRush.Source.Active).GetDeclaringType()

PS I understand that I didn't answer on yor question, but hope this will give you a direction to search a solution

Not sure about native VS addons implementation, but if you are using DevExpress.CodeRush, goto definition functionality should be based on current position in source file, and do something like this to retrieve reference to declaring type:
((TypeReferenceExpression)CodeRush.Source.Active).GetDeclaringType()

P.S. I understand that I didn't answer on yor question, but hope this will give you a direction to search a solution

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文