private void GenerateFromProcedures(string baseNamespace, IDictionary <string, StringBuilder> lookup, StringBuilder output) { foreach (ProcedureDefinition procedure in session.Schema.Procedures) { string classNamespace = CodeFormat.ToPascalCase(procedure.Owner); // Separate tables into namespace buckets. StringBuilder value; if (lookup.TryGetValue(classNamespace, out value)) { value.AppendLine(procedureProcessor.GenerateProcedure(procedure)); value.AppendLine(); } else { if (!Compare.AreSameOrdinalIgnoreCase(procedure.Owner, "dbo")) { output.AppendLine(string.Format("using {0};", baseNamespace.Length > 0 ? baseNamespace + "." + classNamespace : classNamespace)); } StringBuilder builder = new StringBuilder(); lookup.Add(classNamespace, builder); builder.AppendLine(procedureProcessor.GenerateProcedure(procedure)); builder.AppendLine(); } } }
///<summary> ///</summary> ///<returns></returns> public string ToProperCase() { if (columnName == null) { throw new InvalidOperationException("The column name has not been set. Unable to generate a proper cased representation of the column."); } return(CodeFormat.ToProperCase(columnName)); }
///<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)); }
private string GenerateEnum(TableDefinition table) { StringBuilder builder = new StringBuilder(); try { using (IDataReader reader = session.ExecuteReader(CodeGenQuery.From(table))) { int count = 0; while (reader.Read()) { string name = reader.GetString(table.ValueOrdinal); if (Compare.IsNullOrEmpty(name)) { name = "Empty"; } if (count > 0) { builder.AppendLine(); } builder.AppendLine(Indent.One + "/// <summary>"); builder.AppendLine(Indent.One + "/// " + name); builder.AppendLine(Indent.One + "/// </summary>"); builder.AppendLine(Indent.One + "[EnumDescription(\"" + name + "\")]"); builder.AppendLine(Indent.One + CodeFormat.ToPascalCase(name, CodeFormatOptions.RemoveFKPrefix) + " = " + Convert.ToInt32(reader[table.KeyOrdinal]) + ","); count++; } builder.Remove(builder.Length - Environment.NewLine.Length - 1, 1); } return(Templates.Enum .Replace(Tokens.ClassName, table.Name) .Replace(Tokens.SchemaName, table.Owner) .Replace(Tokens.TableName, table.Name) .Replace(Tokens.EnumValues, builder.ToString())); } catch (InvalidCastException ex) { builder.AppendLine("/*"); builder.AppendLine("While attempting to generate an enum, this table failed with the following exception:"); builder.AppendLine(ex.ToString()); builder.AppendLine("*/"); builder.AppendLine(classProcessor.GenerateClass(table)); } return(builder.ToString()); }
private void GenerateFromViews(string baseNamespace, IDictionary <string, StringBuilder> lookup, StringBuilder output) { foreach (TableDefinition table in session.Schema.Tables) { if (!table.IsReadOnly) { continue; } string classNamespace = CodeFormat.ToPascalCase(table.Owner); // Separate tables into namespace buckets. StringBuilder value; if (lookup.TryGetValue(classNamespace, out value)) { if (table.IsEnum) { value.AppendLine(GenerateEnum(table)); value.AppendLine(); } else { value.AppendLine(classProcessor.GenerateClass(table)); value.AppendLine(); } } else { if (!Compare.AreSameOrdinal(table.Owner, "dbo")) { output.AppendLine(string.Format("using {0};", baseNamespace.Length > 0 ? baseNamespace + "." + classNamespace : classNamespace)); } StringBuilder builder = new StringBuilder(); lookup.Add(classNamespace, builder); if (table.IsEnum) { builder.AppendLine(GenerateEnum(table)); builder.AppendLine(); } else { builder.AppendLine(classProcessor.GenerateClass(table)); builder.AppendLine(); } } } }
///<summary> ///</summary> ///<returns></returns> public string ToProperCase() { return(CodeFormat.ToProperCase(name)); }
///<summary> ///</summary> ///<returns></returns> public string ToPascalCase() { return(CodeFormat.ToPascalCase(name, CodeFormatOptions.None)); }
///<summary> ///</summary> ///<returns></returns> public string ToCamelCase() { return(CodeFormat.ToCamelCase(name)); }
public string ToPascalCase(CodeFormatOptions formatOptions) { return(CodeFormat.ToPascalCase(name, formatOptions)); }
public string ToPascalCase() { return(CodeFormat.ToPascalCase(name, CodeFormatOptions.RemoveFKPrefix)); }