c# - 在 VSIX Visual Studio 可扩展性中,如何获取函数的参数是“ref”、“out”还是值类型
问题描述
我在项目中运行 VSIX 的功能是这样的;
public void Method1(string name, out int age)
{
age = 0;
int g1 = 0;
//
int g = 0;
}
并且检查函数参数的 VSIX 项目代码是
// Here 'codeElement' is the Function Having Parameters.
foreach (CodeElement codeElement2 in codeElement.Children)
{
if (codeElement2.Kind == vsCMElement.vsCMElementParameter)
{
string parameterName = codeElement2.Name;
string parameterDataType = ((CodeParameter)codeElement2).Type.AsString;
VsShellUtilities.ShowMessageBox(
this.package,
">>>>>" + " : " + parameterName + " : " + parameterDataType,
"MESSAGE...",
OLEMSGICON.OLEMSGICON_INFO,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
此代码工作正常,它给出了参数的名称及其数据类型。
如何获取参数是“out”、“ref”还是值类型?
(就像 Method1 中的参数 'age' 是一个 'out')
解决方案
使用包含更多信息的CodeParameter2接口:
((CodeParameter2)codeElement2).ParameterKind
推荐阅读
- flutter - Flutter:TabBar 剪辑标签标题
- regex - 当新行在数据中时计算txt文件中的行数
- python - 过滤具有交叉列重叠值的 DataFrame 行
- karate - 空手道 - 如何在空手道中使用嵌套,类似于 javascript
- ubuntu-18.04 - 在 ubuntu 18.04 中安装 R 4.0.2
- python - 我怎样才能使 long if else 和 strings 通用?
- mysql - 在同一台 Linux(Ubuntu)机器上安装 MySQL 5.* 和 MySQL 8?
- python - 在 Python 中求解方程很热门?哪个相当于 Matlab 的 ode45?
- javascript - Uncaught (in promise): TypeError: this.categoryMap.get is not a function
- regex - 我可以使用正则表达式条件而不将它们作为结果的一部分吗?