[英]VS 2015 Addin: Name and type of object at the current text point
I am trying to determine the name and the type (wheter the object is a method, property, etc.) of the element in which the caret is currently placed for a Visual Studio Plugin. 我正在尝试确定当前用于Visual Studio插件的插入符号的元素的名称和类型(对象是方法,属性等)。 I already tried to use CodeElements, but I'm just able to receive the elements declared in the current document and found no way to get the desired information.
我已经尝试使用CodeElements,但是我只能够接收当前文档中声明的元素,却找不到获取所需信息的方法。
Example: 例:
Console.Wr|iteLine(); // Caret is placed after the 'r'
In above's short example, I want to receive "WriteLine" as the current object's name and I'd like to know that it is a method. 在上面的简短示例中,我想接收“ WriteLine”作为当前对象的名称,并且我想知道它是一个方法。 Is there a simple way to do this?
有没有简单的方法可以做到这一点? Any help is welcome.
欢迎任何帮助。
Thanks in advance 提前致谢
I recommend to use Roslyn code analysis. 我建议使用Roslyn代码分析。 See for example Create a typed variable from the current method invocation .
例如,请参见从当前方法调用创建类型化变量 。 It finds Microsoft.CodeAnalysis.IMethodSymbol from the current text point.
它从当前文本点找到Microsoft.CodeAnalysis.IMethodSymbol。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.