首页 > 解决方案 > 在 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')

标签: c#visual-studiovisual-studio-extensionsvs-extensibility

解决方案


使用包含更多信息的CodeParameter2接口:

((CodeParameter2)codeElement2).ParameterKind

推荐阅读