C# 如何从CodeFunction获得函数的定义?

C# 如何从CodeFunction获得函数的定义?,c#,visual-studio-extensions,envdte,visual-studio-sdk,C#,Visual Studio Extensions,Envdte,Visual Studio Sdk,我确实有一个来自EnvDTE命名空间的CodeFunction对象。我想知道它的定义;e、 g: private void MenuItemCallback(object sender, EventArgs e) { MessageBox.Show("Try"); } 我想把第一行作为字符串 我到现在为止所尝试的 1)通过获取CodeFunction的类型(返回类型)和参数,然后在循环中将它们添加到字符串中,尝试生成字符串。但是,参数类型的名称变得像“System.UInt32”等,这

我确实有一个来自EnvDTE命名空间的CodeFunction对象。我想知道它的定义;e、 g:

private void MenuItemCallback(object sender, EventArgs e)
{
    MessageBox.Show("Try");
}
我想把第一行作为字符串

我到现在为止所尝试的

1)通过获取CodeFunction的类型(返回类型)和参数,然后在循环中将它们添加到字符串中,尝试生成字符串。但是,参数类型的名称变得像“System.UInt32”等,这是我不想看到的。这也是一个问题,它可能无法完全接受
ref Guid pguidCmdGroup
。我害怕在这件事上跳过裁判

2)我尝试使用CodeFunction的函数,但我只能得到它的简单名称

3)我试图从CodeFunction的起点和终点开始编写,但找不到将两个TextPoint转换为string的方法,我意识到终点不是定义的终点,而是函数本身,我不想这样做

我如何只获取
private void MenuItemCallback(objectsender,EventArgs e)
MenuItemCallback(objectsender,EventArgs e)

感谢您的帮助。

您必须使用GetStartPoint()和GetEndPoint():
读取函数的完整源代码,然后切断 在第一个打开的花括号之前编码

// Retrieve the source code for the function.
TextPoint start = codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader);
TextPoint finish = codeFunction.GetEndPoint();

string fullSource = start.CreateEditPoint().GetText(finish);

// Find the first open curly brace
int openCurlyBracePos = fullSource.IndexOf('{');

string declaration = String.Empty;
if (openCurlyBracePos > -1) {
    declaration = fullSource.Substring(0, openCurlyBracePos).Trim();
}

如果这不可能,我也不会感到惊讶。在编译过程中,
字符串
代码被翻译成机器语言。可能有一些扩展可以在编辑器或活动文档上进行编辑/搜索等,所以没有办法获得方法的定义吗?