Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually, I think the first thing you need to do is to judge how many methods or properties in your class and what's the position of them. After you obtain those information. The next step you need to do is to judge what's the current cursor position now. Then you can do a compare with those methods information you obtained. Until now, you can get which method that your cursor in. This is a ballpark solution that I find.</p> <p>Let's talk about some technical details:</p> <p><strong>1.How to get the positions of methods and properties?</strong></p> <p>you can use <a href="https://github.com/icsharpcode/NRefactory" rel="nofollow">NRefacotry</a> or <a href="http://csparser.codeplex.com/" rel="nofollow">CSParser</a> to do this (I use NRefactory to finish my requirement)</p> <p><strong>2.How to get cursor position?</strong></p> <p>there is a method named "GetCaretPos" in IVsTextView. You can get ActiveTextView through TextManager. Then you could use "GetCaretPos" method. Here are some codes may help you.</p> <pre><code> public static IVsTextManager TextManager { get { if (textManager == null) { Object obj = Package.GetGlobalService(typeof(SVsTextManager)); if (obj == null) { throw new ArgumentException("get textmanager failed in VSTextView"); } textManager = obj as IVsTextManager; } return textManager; } } public static IVsTextView ActiveTextView { get { IVsTextView activeView = null; if (TextManager != null) { TextManager.GetActiveView(1, activeTextBuffer, out activeView); } return activeView; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload