在C#的此代码段中跟踪我的错误? [英] Trace my mistake in this Code Snippet in C#?
本文介绍了在C#的此代码段中跟踪我的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我只想使用开关盒而不是注释行
如果默认值是整数.所以这里我的代码不起作用.请追踪我的错误.
Here I just want to use the switch case instead of commented lines
if the defualt value is an integer. So here my code is not working. Please trace my mistake.
ParameterInfo[] pif = m.GetParameters();
foreach (ParameterInfo p in pif)
{
string ParamType = p.ParameterType.ToString();
string ConvPType = ConvertToShortForm(ParamType);
if (p.IsOut)
{
ConvPType = ConvPType.Replace("ref", "out");
}
strMethodName += ConvPType;
strMethodName += " ";
strMethodName += p.Name;
if (p.IsOptional)
{
var optional_value = p.DefaultValue;
switch (optional_value)
{
case "":
strMethodName += @"""" + @"""";
break;
case null:
strMethodName = strMethodName + "=" + "null";
break;
case "False":
strMethodName += " = " + p.DefaultValue.ToString().ToLower();
break;
default: strMethodName += ", ";
break;
}
//if (p.DefaultValue != null)
// strMethodName += " = " + p.DefaultValue.ToString().ToLower();
//if (p.DefaultValue == null)
// strMethodName = strMethodName + "=" + "null";
//if (strMethodName.EndsWith("= "))
// strMethodName += @"""" + @"""";
推荐答案
一方面,如果它是布尔类型,则应检查case false
而不是case "False".
For one thing, if this is a of type boolean, you should be checking againstcase false
and notcase "False".
这篇关于在C#的此代码段中跟踪我的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文