Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        ///<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));
        }
Exemplo n.º 3
0
        ///<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));
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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();
                    }
                }
            }
        }
Exemplo n.º 6
0
 ///<summary>
 ///</summary>
 ///<returns></returns>
 public string ToProperCase()
 {
     return(CodeFormat.ToProperCase(name));
 }
Exemplo n.º 7
0
 ///<summary>
 ///</summary>
 ///<returns></returns>
 public string ToPascalCase()
 {
     return(CodeFormat.ToPascalCase(name, CodeFormatOptions.None));
 }
Exemplo n.º 8
0
 ///<summary>
 ///</summary>
 ///<returns></returns>
 public string ToCamelCase()
 {
     return(CodeFormat.ToCamelCase(name));
 }
 public string ToPascalCase(CodeFormatOptions formatOptions)
 {
     return(CodeFormat.ToPascalCase(name, formatOptions));
 }
Exemplo n.º 10
0
 public string ToPascalCase()
 {
     return(CodeFormat.ToPascalCase(name, CodeFormatOptions.RemoveFKPrefix));
 }