从 Visual Studio 加载项访问可用类型列表?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定本机 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
稍后,如果我有时间,请参阅 http: //msdn.microsoft.com/en-us/library/system.componentmodel.design.ityperesolutionservice.aspx。
More details later, if I get time, but see http://msdn.microsoft.com/en-us/library/system.componentmodel.design.ityperesolutionservice.aspx.