其实我觉得你需要做的第一件事就是判断你班上有多少方法或属性,以及他们的位置是什么。获得这些信息后。下一步你需要做的是判断当前光标的位置。然后,您可以对您获得的方法信息进行比较。到现在为止,你可以得到你的光标所在的方法。这是我找到的一个球场解决方案。
让我们的一些技术细节的谈话:
1.How获得的方法和属性的位置?
可以使用NRefacotry或CSParser做到这一点(我用NRefactory完成我的要求)
2.How得到光标位置?
有一个在IVsTextView名为 “GetCaretPos” 的方法。您可以通过TextManager获取ActiveTextView。然后你可以使用“GetCaretPos”方法。这里有一些代码可以帮助你。
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;
}
}
我猜你是指脱口而不是光标。 TextPoint.CodeElement是关键属性。 – 2012-01-03 18:39:37
感谢@HansPassant,我编辑了这个问题。 – Faredoon 2012-01-12 03:29:12