public string GenerateProcedure(ProcedureDefinition definition)
        {
            StringBuilder parameterBuilder = new StringBuilder();

            foreach (ProcedureParameterDefinition parameterInfo in definition.Parameters)
            {
                parameterBuilder.AppendLine(Indent.Two + "public static ICallableParameter " + parameterInfo.ToPascalCase() + "{");
                parameterBuilder.AppendLine(Indent.Three + "get { return CreateParameter(\"" + parameterInfo.ToPascalCase() + "\", typeof(" + definition.ToPascalCase() + ")); }");
                parameterBuilder.AppendLine(Indent.Two + "}");
                parameterBuilder.AppendLine();
            }

            string        className       = definition.ToPascalCase();
            TablesElement procedureConfig = session.GetTableConfiguration(definition.Owner, definition.Name);

            if (procedureConfig != null)
            {
                if (!Compare.IsNullOrEmpty(procedureConfig.RenameTo))
                {
                    className = procedureConfig.RenameTo;
                }

                if (!Compare.IsNullOrEmpty(procedureConfig.AddPrefix))
                {
                    className = procedureConfig.AddPrefix + className;
                }
                if (!Compare.IsNullOrEmpty(procedureConfig.AddSuffix))
                {
                    className += procedureConfig.AddSuffix;
                }
            }

            return(Templates.ProcedureClass.Replace(Tokens.SchemaAttributes, GenerateProcedureAttribute(definition)).Replace(Tokens.ParameterList, parameterBuilder.ToString()).Replace(Tokens.ClassName, className).Replace(Tokens.SchemaName, definition.Owner).Replace(Tokens.ProcedureName, definition.Name).Replace(Tokens.Properties, GenerateProcedureProperties(definition)));
        }
Exemple #2
0
        private string GenerateClassInternal(TableDefinition table)
        {
            StringBuilder columnBuilder = new StringBuilder();
            StringBuilder fieldBuilder  = new StringBuilder();

            fieldBuilder.AppendLine();
            foreach (TableColumnDefinition column in table.Columns)
            {
                if (column.IsForeignKey && column.ForeignKeyColumn != null && column.ForeignKeyColumn.ParentTable.IsEnum)
                {
                    columnBuilder.AppendLine(Indent.Three + "public static QueryColumn " + column.ForeignKeyColumn.ParentTable.ToPascalCase() + "\r\n            {");
                }
                else
                {
                    columnBuilder.AppendLine(Indent.Three + "public static QueryColumn " + column.ToPascalCase() + "\r\n            {");
                }

                columnBuilder.AppendLine(Indent.Four + "get { return FetchColumn(\"" + column.Name + "\"); }");
                columnBuilder.AppendLine(Indent.Three + "}");
                columnBuilder.AppendLine();

                if (column.IsForeignKey && column.ForeignKeyColumn != null && column.ForeignKeyColumn.ParentTable.IsEnum)
                {
                    string enumType = column.ForeignKeyColumn.ParentTable.ToPascalCase();
                    fieldBuilder.AppendLine(Indent.Two + "private " + enumType + " _" + column.Name.ToCamelCase() + ";");
                }
                else
                {
                    fieldBuilder.AppendLine(Indent.Two + "private " + column.GetDataTypeShort() + " _" + column.Name.ToCamelCase() + ";");
                }
            }

            string        className   = table.ToPascalCase().Singularize(Plurality.CouldBeEither);
            TablesElement tableConfig = session.GetTableConfiguration(table.Owner, table.Name);

            if (tableConfig != null)
            {
                if (!Compare.IsNullOrEmpty(tableConfig.RenameTo))
                {
                    className = tableConfig.RenameTo;
                }
                if (!Compare.IsNullOrEmpty(tableConfig.AddPrefix))
                {
                    className = tableConfig.AddPrefix + className;
                }
                if (!Compare.IsNullOrEmpty(tableConfig.AddSuffix))
                {
                    className += tableConfig.AddSuffix;
                }
            }

            return(processorState.ClassTemplate.Replace(Tokens.SchemaAttributes, GenerateTableAttribute(table)).Replace(Tokens.AdditionalAttributes, string.Empty).Replace(Tokens.ClassName, className).Replace(Tokens.SchemaName, table.Owner).Replace(Tokens.TableName, table.Name).Replace(Tokens.PrimaryKeyColumn, table.PrimaryKey == null ? "null" : table.ToPascalCase() + "Columns." + table.PrimaryKey.ToPascalCase()).Replace(Tokens.Properties, GenerateProperties(table)).Replace(Tokens.ColumnList, columnBuilder.ToString()).Replace(Tokens.TargetNamespace, serializationNamespace).Replace(Tokens.AllowNillable, allowNillable).Replace(Tokens.MemberFields, fieldBuilder.ToString()));
        }