/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static string ToPascalCase(this string value) { if (String.IsNullOrEmpty(value)) { return(value); } if (value.IndexOf('_') >= 0) { var parts = value.Split('_'); var sb = StringBuilderThreadStatic.Allocate(); foreach (var part in parts) { var str = part.ToCamelCase(); sb.Append(char.ToUpper(str[0]) + str.SafeSubstring(1, str.Length)); } return(StringBuilderThreadStatic.ReturnAndFree(sb)); } var camelCase = value.ToCamelCase(); return(char.ToUpper(camelCase[0]) + camelCase.SafeSubstring(1, camelCase.Length)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static string ToLowercaseUnderscore(this string value) { if (String.IsNullOrEmpty(value)) { return(value); } value = value.ToCamelCase(); var sb = StringBuilderThreadStatic.Allocate(); foreach (char t in value) { if (char.IsDigit(t) || (char.IsLetter(t) && char.IsLower(t)) || t == '_') { sb.Append(t); } else { sb.Append("_"); sb.Append(char.ToLowerInvariant(t)); } } return(StringBuilderThreadStatic.ReturnAndFree(sb)); }