0
我只想使用switch语句而不是下面的注释行。 如果默认值是一个整数。在C#代码片段中跟踪我的错误?
所以在这里我的代码不工作,请确定我的错误。
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 += @"""" + @"""";
不错的格式化 – Svisstack 2010-10-12 11:23:12
所以评论行是正确的和工作,你想重构他们? – 2010-10-12 11:24:24
错误在哪里,错误是什么? – 2010-10-12 11:28:53