Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
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 += @"""" + @"""";
Posted
Updated 12-Oct-10 2:51am
v2
Comments
Alan N 12-Oct-10 7:42am    
Please clarify the type of DefaultValue and also what "not working" means.

1 solution

For one thing, if this is a of type boolean, you should be checking against case false and not case "False".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900