当前位置: 首页>>代码示例>>C#>>正文


C# CodeWriter.WriteLineFormat方法代码示例

本文整理汇总了C#中CodeWriter.WriteLineFormat方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.WriteLineFormat方法的具体用法?C# CodeWriter.WriteLineFormat怎么用?C# CodeWriter.WriteLineFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeWriter的用法示例。


在下文中一共展示了CodeWriter.WriteLineFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateClass

 public override string GenerateClass(Schema schema)
 {
     CodeWriter writer = new CodeWriter();
     string className = "DataStore";
     writer.WriteLine(USING_STRING);
     writer.WriteLine();
     writer.WriteLine("namespace DataAccess");
     writer.WriteLine("{");
     writer.PushIdent();
     writer.WriteLineFormat("public class {0}: DatabaseContext, IDataStore", className);
     writer.WriteLine("{");
     writer.PushIdent();
     writer.WriteLineFormat("public {0}(IDbConnection connection, IDbTransaction transaction) : base(connection, transaction) {{ }}", className);
     writer.WriteLineFormat("public {0}(IDbConnection connection) : base(connection, null) {{ }}", className);
     writer.WriteLine();
     
     foreach (StoredProcedure sp in schema.StoredProcedures)
     {
         string methodHeader = "public " + generateMethodHeader(sp);
         string methodBody = GenerateMethodBody(sp);
         writer.WriteLine(methodHeader);
         writer.WriteLine(methodBody);
         writer.WriteLine();
     }
     writer.PopIdent();
     writer.WriteLine("}");
     writer.PopIdent();
     writer.WriteLine("}");
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:30,代码来源:CSharpDataAccessGenerator.cs

示例2: GenerateClass

        public string GenerateClass(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine(HEADER);
            writer.WriteLineFormat("package {0}", service.Name);
            writer.WriteLine("{");
            writer.PushIdent();
            writer.WriteLine(IMPORT);
            writer.WriteLine();
            writer.WriteLineFormat("public class {0}Client", intr.Name);
            writer.WriteLine("{");
            writer.PushIdent();
            writer.WriteLine("public var url: String = \"\";");
            writer.WriteLine(LOAD);
            writer.WriteLine();

            foreach(Method method in intr.Methods)
            {
                writer.WriteLine(GenerateMethodHeader(intr, method));
                writer.WriteLine("{"); 
                writer.PushIdent();
                writer.WriteLine(GenerateMethodBody(intr, method));
                writer.PopIdent();
                writer.WriteLine("}");
                writer.WriteLine();
            }
            writer.PopIdent();
            writer.WriteLine("}");
            writer.PopIdent();
            writer.WriteLine("}");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:32,代码来源:FlexGenerator.cs

示例3: GenerateDropIfExists

 private string GenerateDropIfExists(string spName)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLineFormat("IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{0}') AND type in (N'P', N'PC'))", spName);
     writer.PushIdent();
     writer.WriteLineFormat("DROP PROCEDURE {0};", spName);
     writer.PopIdent();
     writer.WriteLine("GO");
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:10,代码来源:SqlServerCrudGenerator.cs

示例4: GenerateSqlCreate

        public override string GenerateSqlCreate(Table table)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLineFormat("create table [{0}].[{1}](", table.Schema.Name, table.Name);
            writer.PushIdent();
            int colCount = table.Columns.Count;
            int conCount = table.Constraints.Count;
            for (int i = 0; i < colCount; i++)
            {
                Column col = table.Columns[i];
                DataType dt = TypeMap == null ? col.DataType : TypeMap.MapDataType(col.DataType);
                string nullDef = col.IsNullable? "null": "not null";
                string autoIncrementDef = col.IsAutoIncremented ? "identity(1, 1)" : "";
                string colDef = string.Format("[{0}] {1} {2} {3}", col.Name, dt.FullName, nullDef, autoIncrementDef).Trim();
                string comma = (i < colCount - 1 || conCount > 0) ? "," : "";
                writer.WriteLineFormat("{0}{1}", colDef, comma);
            }

            
            for (int i = 0; i < conCount; i++)
            {
                TableConstraint con = table.Constraints[i];
                string conDef = null;
                if (con.Type == ConstraintType.PrimaryKey)
                {
                    string colDef = StringUtils.GenerateCommaSeparatedString(con.Columns, "[", "]");
                    conDef = string.Format("constraint [{0}] primary key({1})", con.Name, colDef);
                }
                else if (con.Type == ConstraintType.Unique)
                {
                    string colDef = StringUtils.GenerateCommaSeparatedString(con.Columns, "[", "]");
                    conDef = string.Format("constraint [{0}] unique({1})", con.Name, colDef);
                }
                else if (con.Type == ConstraintType.Check)
                {
                    CheckConstraint chk = (CheckConstraint)con;
                    conDef = string.Format("constraint [{0}] check {1}", chk.Name, chk.Clause);
                }
                else if (con.Type == ConstraintType.ForeignKey)
                {
                    ForeignKeyConstraint fk = (ForeignKeyConstraint)con;
                    string colDef = StringUtils.GenerateCommaSeparatedString(fk.Columns, "[", "]");
                    string refColDef = StringUtils.GenerateCommaSeparatedString(fk.ReferencedColumns, "[", "]");
                    conDef = string.Format("constraint [{0}] foreign key({1}) references [{2}].[{3}]({4}) on update {5} on delete {6}", 
                        fk.Name, colDef, con.Table.Schema.Name, fk.ReferencedTable, refColDef, fk.UpdateRule, fk.DeleteRule);
                }
                string comma = i < conCount - 1 ? "," : "";
                writer.WriteLineFormat("{0}{1}", conDef, comma);
            }

            writer.PopIdent();
            writer.Write(")");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:54,代码来源:SqlServerDatabaseGenerator.cs

示例5: GenerateSqlCreate

        public override string GenerateSqlCreate(Table table)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine("DELIMITER $$");
            writer.WriteLineFormat("create table `{0}`.`{1}`(", table.Schema.Name, table.Name);
            writer.PushIdent();
            int colCount = table.Columns.Count;
            int conCount = table.Constraints.Where(c => c.Type != ConstraintType.Check).Count();
            for (int i = 0; i < colCount; i++)
            {
                Column col = table.Columns[i];
                DataType dt = TypeMap == null ? col.DataType : TypeMap.MapDataType(col.DataType);
                string nullDef = col.IsNullable? "null": "not null";
                string autoIncrementDef = col.IsAutoIncremented ? "auto_increment" : "";
                string colDef = string.Format("`{0}` {1} {2} {3}", col.Name, dt.FullName, nullDef, autoIncrementDef).Trim();
                string comma = (i < colCount - 1 || conCount > 0) ? "," : "";
                writer.WriteLineFormat("{0}{1}", colDef, comma);
            }

            
            for (int i = 0; i < conCount; i++)
            {
                TableConstraint con = table.Constraints[i];
                string conDef = null;
                if (con.Type == ConstraintType.PrimaryKey)
                {
                    string colDef = StringUtils.GenerateCommaSeparatedString(con.Columns, "`", "`");
                    conDef = string.Format("constraint `{0}` primary key({1})", con.Name, colDef);
                }
                else if (con.Type == ConstraintType.Unique)
                {
                    string colDef = StringUtils.GenerateCommaSeparatedString(con.Columns, "`", "`");
                    conDef = string.Format("constraint `{0}` unique({1})", con.Name, colDef);
                }
                else if (con.Type == ConstraintType.ForeignKey)
                {
                    ForeignKeyConstraint fk = (ForeignKeyConstraint)con;
                    string colDef = StringUtils.GenerateCommaSeparatedString(fk.Columns, "`", "`");
                    string refColDef = StringUtils.GenerateCommaSeparatedString(fk.ReferencedColumns, "`", "`");
                    conDef = string.Format("constraint `{0}` foreign key({1}) references `{2}`.`{3}`({4}) on update {5} on delete {6}", 
                        fk.Name, colDef, con.Table.Schema.Name, fk.ReferencedTable, refColDef, fk.UpdateRule, fk.DeleteRule);
                }
                string comma = i < conCount - 1 ? "," : "";
                writer.WriteLineFormat("{0}{1}", conDef, comma);
            }

            writer.PopIdent();
            writer.Write(")$$");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:50,代码来源:MySqlDatabaseGenerator.cs

示例6: generateInsertBody

        private string generateInsertBody(Table table, List<Column> insertableColumns)
        {
            List<string> colNames = new List<string>();
            foreach (Column col in insertableColumns)
            {
                colNames.Add(col.Name);
            }

            CodeWriter writer = new CodeWriter();
            writer.WriteLineFormat("INSERT INTO [{0}].[{1}]", table.Schema.Name, table.Name);
            writer.WriteLineFormat("({0})", StringUtils.GenerateCommaSeparatedString(colNames, "[", "]"));
            writer.WriteLine("VALUES");
            writer.WriteLineFormat("({0});", StringUtils.GenerateCommaSeparatedString(colNames, "@", ""));
            writer.WriteLine("RETURN SCOPE_IDENTITY();");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:16,代码来源:SqlServerCrudGenerator.cs

示例7: generateUpdateBody

        private string generateUpdateBody(Table table, List<Column> keyColumns, List<Column> updateColumns)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLineFormat("UPDATE [{0}].[{1}]", table.Schema.Name, table.Name);
            writer.WriteLine("SET");
            writer.PushIdent();
            for (int i = 0; i < updateColumns.Count; i++)
            {
                Column column = updateColumns[i];
                string and = i < updateColumns.Count - 1 ? "," : "";
                string cond = string.Format("[{0}] = @{0} {1}", column.Name, and).Trim();
                writer.WriteLine(cond);
            }
            writer.PopIdent();

            writer.WriteLine("WHERE");
            writer.PushIdent();
            for (int i = 0; i < keyColumns.Count; i++)
            {
                Column column = keyColumns[i];
                string and = i < keyColumns.Count - 1 ? "AND" : "";
                string cond = string.Format("[{0}] = @{0} {1}", column.Name, and).Trim();
                writer.WriteLine(cond);
            }
            writer.PopIdent();
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:27,代码来源:SqlServerCrudGenerator.cs

示例8: Generate

 public override string Generate(Schema schema)
 {
     CodeWriter writer = new CodeWriter();
     foreach (Table table in schema.Tables)
     {
         writer.WriteLineFormat("-- {0} --", table.Name);
         writer.WriteLine(GenerateInsert(table));
         writer.WriteLineFormat("GO");
         writer.WriteLine(GenerateUpdate(table));
         writer.WriteLine(GenerateDelete(table));
         writer.WriteLine(GenerateGetAll(table));
         writer.WriteLine("GO");
         writer.WriteLine(GenerateGet(table));
         writer.WriteLine();
     }
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:17,代码来源:SqlServerCrudGenerator.cs

示例9: GenerateTables

 public override string GenerateTables(Schema schema)
 {
     CodeWriter writer = new CodeWriter();
     foreach(Table table in schema.Tables)
     {
         writer.WriteLineFormat("-- {0} --", table.Name);
         writer.WriteLine(GenerateSqlCreate(table));
         writer.WriteLine();
     }
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:11,代码来源:MySqlDatabaseGenerator.cs

示例10: GenerateStoredProcedures

 public override string GenerateStoredProcedures(Schema schema)
 {
     CodeWriter writer = new CodeWriter();
     foreach (StoredProcedure sp in schema.StoredProcedures)
     {
         writer.WriteLineFormat("-- {0} --", sp.Name);
         sp.Definition = DUMMY_BODY;
         writer.WriteLine(GenerateStoredProcedureCreate(sp));
         writer.WriteLine();
     }
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:12,代码来源:MySqlDatabaseGenerator.cs

示例11: Generate

        public IDictionary<string, string> Generate(Service service)
        {
            IDictionary<string, string> files = new Dictionary<string, string>();

            CodeWriter writer = new CodeWriter();
            writer.WriteLineFormat("angular.module(\"{0}\", [])", service.Name);
            writer.PushIdent();
            writer.WriteLine(".constant('serviceUrl', 'http://localhost:8800/Server/handler.ashx')");
            writer.WriteLine();

            foreach (Interface intr in service.Interfaces)
            {
                string code = GenerateInterface(service, intr);
                writer.WriteLine(code);
            }
            string fileName = service.Name + ".js";
            files[fileName] = writer.Code;
            return files;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:19,代码来源:AngularGenerator.cs

示例12: GenerateInsert

 public override string GenerateInsert(Table table)
 {
     CodeWriter writer = new CodeWriter();
     StoredProcedure sp = new StoredProcedure();
     sp.Schema = table.Schema;
     sp.Name = string.Format("HXF_{0}_INSERT", table.Name);
     IEnumerable<Column> insertableColumns = table.Columns.Where<Column>(c => !(c.IsComputed || c.IsAutoIncremented));
     List<Parameter> parameters = new List<Parameter>();
     int i = 0;
     foreach (Column col in insertableColumns)
     {
         Parameter p = new Parameter();
         p.Name = "@" + col.Name;
         p.Position = i++;
         p.DataType = col.DataType.Clone();
         p.Mode = "IN";
         parameters.Add(p);
     }
     sp.Parameters = parameters;
     sp.Definition = generateInsertBody(table, insertableColumns.ToList<Column>());
     string s = new SqlServerDatabaseGenerator(TypeMap).GenerateStoredProcedureCreate(sp).Trim();
     writer.WriteLineFormat("-- {0} --", sp.Name);
     writer.WriteLine(GenerateDropIfExists(sp.Name));
     writer.WriteLine();
     writer.WriteLineFormat(s);
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:27,代码来源:SqlServerCrudGenerator.cs

示例13: GenerateUpdate

        public override string GenerateUpdate(Table table)
        {
            CodeWriter writer = new CodeWriter();
            foreach (TableConstraint constraint in table.Constraints)
            {
                if (constraint.Type == ConstraintType.PrimaryKey || constraint.Type == ConstraintType.Unique)
                {
                    StoredProcedure sp = new StoredProcedure();
                    sp.Parameters = new List<Parameter>();
                    sp.Schema = table.Schema;
                    List<string> colNames = constraint.Columns;
                    string sepStrings = StringUtils.GenerateSeparatedString(colNames, "_AND_", "", "");
                    sp.Name = string.Format("HXF_{0}_UPDATE_BY_{1}", table.Name, sepStrings);
                    // columns that are part of key constraint is used in where clause
                    IEnumerable<Column> keyColumns = table.Columns.Where<Column>(c => colNames.Contains(c.Name));
                    
                    // columns that can be updated
                    IEnumerable<Column> updatableColumns = table.Columns.Where<Column>(c => !(c.IsComputed || c.IsAutoIncremented));
                    
                    // columns that will be part of update statement
                    IEnumerable<Column> updateColumns = updatableColumns.Except(keyColumns);
                    if (updateColumns.Count() > 0)
                    {
                        string body = generateUpdateBody(table, keyColumns.ToList<Column>(), updateColumns.ToList<Column>());

                        // create parameters for columns used in the stored procedure
                        foreach (Column column in keyColumns.Union(updatableColumns))
                        {
                            Parameter p = new Parameter();
                            p.StoredProcedure = sp;
                            p.Name = "@" + column.Name;
                            //p.Direction = ParameterDirection.In;
                            p.Mode = "IN";
                            p.DataType = TypeMap != null ? TypeMap.MapDataType(column.DataType) : column.DataType;
                            sp.Parameters.Add(p);
                            sp.Definition = body;
                        }
                        SqlServerDatabaseGenerator gen = new SqlServerDatabaseGenerator(TypeMap);
                        string s = gen.GenerateStoredProcedureCreate(sp).Trim();
                        writer.WriteLineFormat("-- {0} --", sp.Name);
                        writer.WriteLine(GenerateDropIfExists(sp.Name));
                        writer.WriteLine();
                        writer.WriteLine(s);
                        writer.WriteLine("GO");
                        writer.WriteLine();
                    }
                    
                    
                }
            }

            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:53,代码来源:SqlServerCrudGenerator.cs

示例14: GenerateStoredProcedureCreate

 public override string GenerateStoredProcedureCreate(StoredProcedure storedProcedure)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLineFormat("CREATE PROCEDURE [{0}].[{1}]", storedProcedure.Schema.Name, storedProcedure.Name);
     int paramCount = storedProcedure.Parameters.Count;
     if (paramCount > 0)
     {
         writer.WriteLine("(");
     }
     writer.PushIdent();
     for (int i = 0; i < paramCount; i++)
     {
         Parameter parameter = storedProcedure.Parameters[i];
         DataType dt = TypeMap == null ? parameter.DataType : TypeMap.MapDataType(parameter.DataType);
         string modeDef = parameter.Mode == "OUT" ? parameter.Mode : "";
         string paramName = parameter.Name.StartsWith("@") ? parameter.Name : "@" + parameter.Name;
         string pDef = string.Format("{0} {1} {2}", paramName, dt.FullName, modeDef).Trim();
         string comma = i < paramCount - 1 ? "," : "";
         writer.WriteLineFormat("{0}{1}", pDef, comma);
     }
     writer.PopIdent();
     if (paramCount > 0)
     {
         writer.WriteLine(")");
     }
     writer.WriteLine("as");
     writer.WriteLine("begin");
     writer.PushIdent();
     writer.WriteLine(storedProcedure.Definition);
     writer.PopIdent();
     writer.Write("end");
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:33,代码来源:SqlServerDatabaseGenerator.cs

示例15: GenerateMethodBody

 public string GenerateMethodBody(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLine("var o: Object = new Object();");
     writer.WriteLine("var p: Object = new Object();");
     writer.WriteLineFormat("o[\"interface\"] = \"{0}\"", intr.Name);
     writer.WriteLineFormat("o[\"method\"] = \"{0}\"", method.Name);
     foreach (Parameter p in method.Parameters)
     {
         writer.WriteLineFormat("p[\"{0}\"]={0};", p.Name);
     }
     writer.WriteLine("o[\"parameters\"] = p;");
     writer.WriteLine("var data: String = JSON.stringify(o);");
     writer.WriteLine("load(data, completeFunction);");
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:16,代码来源:FlexGenerator.cs


注:本文中的CodeWriter.WriteLineFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。