所有方法参数的.NET思考 [英] .NET Reflection of all method parameters

查看:186
本文介绍了所有方法参数的.NET思考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能得到的参数名称(在那里我有parmName以下)? 或者,也许在MSIL code,只有相对的位置​​上,没有绝对的PARM名字?

Is it possible to get the parameter name (where I have parmName below)? Or perhaps in the MSIL code there are only relative positions, no absolute parm names?

我在使用微软主机集成服务器内HIP的unusualy情况。当字段是空和误差可以追溯到CICS(在大型机),错误是打电话给VERIFYINVOKEPARAMS失败。我有硬codeD的解决方案,而是试图让一个将适用于任何HIP子程序通用的解决方案。

I have an unusualy case using HIP within Microsoft Host Integration Server. When fields are NULL and the error goes back to CICS (on the mainframe), the error is "A CALL TO VERIFYINVOKEPARAMS FAILED". I have hard-coded a solution, but was trying to make a general solution that would work for any HIP subroutine.

谢谢

尼尔·沃尔特斯

    // check for null values in any of the parameters 
    MethodBase method = MethodBase.GetCurrentMethod();
    //string key = method.Name + "(";
    for (int i = 0; i < method.GetParameters().Length; i++)
    {
        if (method.GetParameters().GetValue(i).GetType() == typeof(String))
        {
            if (method.GetParameters().GetValue(i) == null)
            {
                string parmName = " Parm #" + i; 
                msg = "Value of return variable " + parmName + " is null (should be blanks)";
                System.Diagnostics.EventLog.WriteEntry("LOGGER", msg, 
                    System.Diagnostics.EventLogEntryType.Error);

            }
        }
    }

额外的信息:     我打电话公布为WCF web服务的BizTalk管弦乐团。当它变得错误,一些字段不serialzied回上述程序。这是这些数值必须是空摆在首位。但CICS /应用程序正在调用我的HIS / HIP程序不喜欢空。

Extra info: I'm calling a BizTalk Orch published as a WCF web service. When it gets errors, some fields are not serialzied back to the above program. This is how the values got to be NULL in the first place. But the CICS/application that is calling my HIS/HIP program doesn't like nulls.

推荐答案

试试这个:

var parameters = MethodBase.GetCurrentMethod().GetParameters();
foreach (ParameterInfo parameter in parameters)
{
    Console.WriteLine(parameter.Name);
}

这篇关于所有方法参数的.NET思考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆