///<summary> ///</summary> ///<param name="formatOptions"></param> ///<returns></returns> public string ToPascalCase(CodeFormatOptions formatOptions) { if (columnName == null) { throw new InvalidOperationException("The column name has not been set. Unable to generate a pascal cased representation of the column."); } return(CodeFormat.ToPascalCase(columnName, formatOptions)); }
public static string Format(string text, CodeFormatOptions options) { StringBuilder formattedText = new StringBuilder(); string ch = ""; string nextCh = ""; string prevCh = ""; int tabSize = 0; for (int i = 0; i < text.Length; i++) { ch = text[i].ToString(); nextCh = ""; prevCh = ""; if (i > 0) { prevCh = text[i - 1].ToString(); } if ((i + 1) < text.Length) { nextCh = text[i + 1].ToString(); } if (ch == "{") { if ((options & CodeFormatOptions.BracketsOnNewline) == CodeFormatOptions.BracketsOnNewline) { formattedText.Append(string.Format("{0}{1}{{0}", Environment.NewLine, RepeatString("\t", tabSize))); } else { formattedText.Append(string.Format(" {{0}", Environment.NewLine)); } tabSize++; } else if (ch == "}") { tabSize--; formattedText.Append(string.Format("{0}}{1}", RepeatString("\t", tabSize), Environment.NewLine)); } else if (ch == "\t") { //We will add our own tabs, so we will just be skipping this character. } else { formattedText.Append(ch); } } return(formattedText.ToString()); }
private static string PreFormatCode(string value, CodeFormatOptions formatOptions) { bool removeKeyIndicators = (formatOptions & CodeFormatOptions.RemoveFKPrefix) == CodeFormatOptions.RemoveFKPrefix; bool removeTblPrefix = (formatOptions & CodeFormatOptions.RemoveTblPrefix) == CodeFormatOptions.RemoveTblPrefix; if (removeKeyIndicators && value.StartsWith("FK_", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(3) + "Id"; } else if (removeKeyIndicators && value.StartsWith("FK", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(2) + "Id"; } if (removeTblPrefix && value.StartsWith("tbl_", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(4); } else if (removeTblPrefix && value.StartsWith("tbl", StringComparison.OrdinalIgnoreCase)) { value = value.Substring(3); } return(value); }
public string ToPascalCase(CodeFormatOptions formatOptions) { return(CodeFormat.ToPascalCase(name, formatOptions)); }
public static string ToCamelCase(string value, CodeFormatOptions formatOptions) { Argument.Assert.IsNotNull(value, nameof(value)); return(PreFormatCode(value, formatOptions).ToCamelCase()); }
public static string ToPascalCase(string value, CodeFormatOptions formatOptions) { Argument.Assert.IsNotNull(value, Argument.Names.value); return(PreFormatCode(value, formatOptions).ToPascalCase()); }