ServiceClientGenerator.GeneratorHelpers.CamelCaseParam C# (CSharp) Method

CamelCaseParam() public static method

Sets the first character of the param to lower, if it's an acronym it lowers it all until the next word
public static CamelCaseParam ( string param ) : string
param string The name of the parameter name for the constructor
return string
        public static string CamelCaseParam(string param)
        {
            if (param.Length < 2 || char.IsUpper(param.ToCharArray()[0]) && char.IsLower(param.ToCharArray()[1]))
            {
                if ((char.ToLower(param.ToCharArray()[0]) + param.Substring(1)).Equals("namespace"))
                {
                    return "awsNamespace";
                }
                return param.Length < 2 ? param.ToLower() : char.ToLower(param.ToCharArray()[0]) + param.Substring(1);
            }

            // If it gets here it's an accronym

            int secondWord = 0;
            for (int i = 0; i < param.ToCharArray().Length - 1; i++)
            {
                if (char.IsUpper(param.ToCharArray()[i]) && char.IsLower(param.ToCharArray()[i + 1]))
                {
                    secondWord = i;
                    break;
                }
                else if (char.IsUpper(param.ToCharArray()[i]) && char.IsUpper(param.ToCharArray()[i + 1]))
                {
                    continue;
                }
            }

            if (secondWord == 0)
            {
                if (param.ToLower().Equals("namespace"))
                {
                    return "awsNamespace";
                }
                return param.ToLower();
            }

            var camelParam = new StringBuilder();
            for (int i = 0; i < secondWord; i++)
            {
                camelParam.Append(char.ToLower(param.ToCharArray()[i]));
            }
            camelParam.Append(param.Substring(secondWord));

            if (camelParam.ToString().Equals("namespace"))
            {
                return "awsNamespace";
            }

            return camelParam.ToString();
        }
    }

Usage Example

Beispiel #1
0
 public static string ToCamelCase(this string s)
 {
     return(GeneratorHelpers.CamelCaseParam(s));
 }
All Usage Examples Of ServiceClientGenerator.GeneratorHelpers::CamelCaseParam