如何使用C#找到一个类或方法的用途? [英] How to use C# to find usages of a class or method?

查看:287
本文介绍了如何使用C#找到一个类或方法的用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,我可以右键单击某个类或方法,并选择查​​找用法。这让我在使用这段代码在我的解决方案的地点列表。我怎么可以这样做,从我的代码?

In Visual Studio, I can right-click a class or method and choose "Find usages". That gives me a list of places in my solution where that piece of code is used. How can I do the same from my code?

推荐答案

您将需要分析你的代码做到这一点。我不认为你可以与反思做到这一点。 MS一直在一个名为罗斯林项目。这是一种用于.NET编译器的API的。它应该为你提供你所需要的。请查看这个发布的罗斯林项目的细节

You would need to parse your code to do this. I don't think you could do it with reflection. MS have been working on a project called Roslyn. This is kind of an API for the .NET compiler. It should provide you with what you need. Check out this post for details of the Roslyn project.

报价:

这开辟了新的机遇VS扩展到编写功能强大的
重构和语言的分析工具,以及允许任何人以
将我们的解析器,语义引擎,代码生成器和
脚本在他们的自己的应用程序。

This opens up new opportunities for VS extenders to write powerful refactorings and language analysis tools, as well as allow anyone to incorporate our parsers, semantic engines, code generators and scripting in their own applications.

这个帖子演示如何使用符号的工作结果
这个帖子回答让所有引用的问题。

This post demonstrates working with symbols.
This post answers the question of getting all references.

这篇关于如何使用C#找到一个类或方法的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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