• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CodeWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: WriteDataContextProcedures

 protected virtual void WriteDataContextProcedures(CodeWriter writer, DbLinq.Schema.Dbml.Database schema, GenerationContext context)
 {
     foreach (var procedure in schema.Functions)
     {
         WriteDataContextProcedure(writer, procedure, context);
     }
 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:CodeGenerator.Procedure.cs


示例2: WriteDataContextCtors

 protected virtual void WriteDataContextCtors(CodeWriter writer, Database schema, Type contextBaseType, GenerationContext context)
 {
     // ctor taking a connections tring
     WriteDataContextCtor(writer, schema, contextBaseType,
            new[] { new ParameterDefinition { Name = "connectionString", Type = typeof(string) } },
            new[] { "connectionString" },
            new[] { typeof(string) },
            context);
     // the two constructors below have the same prototype, so they are mutually exclusive
     // the base class requires a IVendor
     if (!WriteDataContextCtor(writer, schema, contextBaseType,
                          new[] { new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) } },
                          new[] { "connection", writer.GetNewExpression(writer.GetMethodCallExpression(writer.GetLiteralFullType(context.SchemaLoader.Vendor.GetType()))) },
                          new[] { typeof(IDbConnection), typeof(IVendor) },
                          context))
     {
         // OR the base class requires no IVendor
         WriteDataContextCtor(writer, schema, contextBaseType,
                              new[] { new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) } },
                              new[] { "connection" },
                              new[] { typeof(IDbConnection) },
                              context);
     }
     // ctor(string, MappingSource)
     WriteDataContextCtor(writer, schema, contextBaseType,
            new[] {
                new ParameterDefinition { Name = "connection", Type = typeof(string) },
                new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
            },
            new[] { "connection", "mappingSource" },
            new[] { typeof(string), typeof (MappingSource) },
            context);
     // ctor(IDbConnection, MappingSource)
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
             },
             new[] { "connection", "mappingSource" },
             new[] { typeof(IDbConnection), typeof(MappingSource) },
             context);
     // just in case you'd like to specify another vendor than the one who helped generating this file
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "vendor", Type = typeof(IVendor) },
             },
             new[] { "connection", "vendor" },
             new[] { typeof(IDbConnection), typeof(IVendor) },
             context);
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
                 new ParameterDefinition { Name = "vendor", Type = typeof(IVendor) },
             },
             new[] { "connection", "mappingSource", "vendor" },
             new[] { typeof(IDbConnection), typeof(MappingSource), typeof(IVendor) },
             context);
 }
开发者ID:nlhepler,项目名称:mono,代码行数:60,代码来源:CodeGenerator.Context.Ctor.cs


示例3: WriteDataContextProcedure

        private void WriteDataContextProcedure(CodeWriter writer, Function procedure, GenerationContext context)
        {
            if (procedure == null || procedure.Name == null)
            {
                //Logger.Write(Level.Error, "CodeGenStoredProc: Error L33 Invalid storedProcedure object");
                writer.WriteCommentLine("error L33 Invalid storedProcedure object");
                return;
            }

            var functionAttribute = NewAttributeDefinition<FunctionAttribute>();
            functionAttribute["Name"] = procedure.Name;
            functionAttribute["IsComposable"] = procedure.IsComposable;

            SpecificationDefinition specifications;
            if (procedure.AccessModifierSpecified)
                specifications = GetSpecificationDefinition(procedure.AccessModifier);
            else
                specifications = SpecificationDefinition.Public;
            if (procedure.ModifierSpecified)
                specifications |= GetSpecificationDefinition(procedure.Modifier);

            using (writer.WriteAttribute(functionAttribute))
            using (writer.WriteMethod(specifications, GetProcedureName(procedure),
                                      GetProcedureType(procedure), GetProcedureParameters(procedure)))
            {
                string result = WriteProcedureBodyMethodCall(writer, procedure, context);
                WriteProcedureBodyOutParameters(writer, procedure, result, context);
                WriteProcedureBodyReturnValue(writer, procedure, result, context);
            }
            writer.WriteLine();
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:CodeGenerator.Procedure.cs


示例4: 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


示例5: GenerateClassSerializer

        public static void GenerateClassSerializer(ProtoMessage m, CodeWriter cw)
        {
            if (m.OptionExternal || m.OptionType == "interface")
            {
                //Don't make partial class of external classes or interfaces
                //Make separate static class for them
                cw.Bracket(m.OptionAccess + " static class " + m.SerializerType);
            }
            else
            {
                cw.Attribute("System.Serializable()");
                cw.Bracket(m.OptionAccess + " partial " + m.OptionType + " " + m.SerializerType);
            }

            GenerateReader(m, cw);

            GenerateWriter(m, cw);
            foreach (ProtoMessage sub in m.Messages.Values)
            {
                cw.WriteLine();
                GenerateClassSerializer(sub, cw);
            }
            cw.EndBracket();
            cw.WriteLine();
            return;
        }
开发者ID:huodianyan,项目名称:ProtoBuf,代码行数:26,代码来源:MessageSerializer.cs


示例6: GenerateInterface

        public string GenerateInterface(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine("define([\"dojo/request\", \"dojo/json\"], function (request, JSON) {");
            writer.PushIdent();
            writer.WriteLine("var serviceClient = {");
            writer.PushIdent();
            writer.WriteLine("urlString: '',");
            writer.WriteLine();

            int methodCount = intr.Methods.Count;
            for (int i = 0; i < methodCount; i++)
            {
                Method method = intr.Methods[i];
                string comma = i < methodCount - 1 ? "," : "";
                writer.Write(GenerateMethod(intr, method).Trim());
                writer.WriteLineNoIdent(comma);
                writer.WriteLine();
            }
            writer.PopIdent();
            writer.WriteLine("}");
            writer.WriteLine("return serviceClient;");
            writer.PopIdent();
            writer.Write("});");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:26,代码来源:JavaScriptDojoAMDGenerator.cs


示例7: SaveHeader

 /// <summary>
 /// Saves the file header to disk.
 /// </summary>
 internal override void SaveHeader(CodeWriter writer, PFile file)
 {
     writer.Write(file.Name);
     writer.Write(new FileInfo(file.FilePath).Length);
     writer.Write(file.LastModified.Ticks);
     writer.Write((int) file.Attributes);
 }
开发者ID:Zyphrax,项目名称:PixelCryptor,代码行数:10,代码来源:PFileComet.cs


示例8: 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


示例9: Translate

 private string Translate(CompilationUnit typedCompilationUnit)
 {
     var code = new CodeWriter();
     WriteAction write = typedCompilationUnit.Visit(csTranslator);
     write(code);
     return code.ToString();
 }
开发者ID:rajeshpillai,项目名称:rook,代码行数:7,代码来源:RookCompiler.cs


示例10: WriteClassHeader

        public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
        {
            using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanging).Name)))
            {
                const string eventName = "PropertyChanging"; // do not change, part of INotifyPropertyChanging
                const string emptyArgs = "emptyChangingEventArgs";

                // event
                writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangingEventHandler).Name);
                writer.WriteLine();
                // empty event arg
                writer.WriteField(SpecificationDefinition.Private | SpecificationDefinition.Static,
                                  writer.GetAssignmentExpression(emptyArgs, writer.GetNewExpression(
                                                                                writer.GetMethodCallExpression(typeof(PropertyChangingEventArgs).Name, "\"\""))),
                                  typeof(PropertyChangingEventArgs).Name);
                // method
                using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual,
                                          sendPropertyChangingMethod, null))
                {
                    using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression())))
                    {
                        writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName,
                                                                                            writer.GetThisExpression(), emptyArgs)));
                    }
                }
            }
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:27,代码来源:INotifyPropertyChangingImplementation.cs


示例11: GenerateInterface

        public string GenerateInterface(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteFormat(".factory(\"{0}Client\", function($http, serviceUrl)", intr.Name);
            writer.WriteLineNoIdent(" {");
            writer.PushIdent();
            writer.WriteLine("return {");

            int methodCount = intr.Methods.Count;
            for (int i = 0; i < methodCount; i++)
            {
                writer.PushIdent();
                Method method = intr.Methods[i];
                string comma = i < methodCount - 1 ? "," : "";
                writer.Write(GenerateMethod(intr, method).Trim());
                writer.WriteLineNoIdent(comma);
                writer.WriteLine();
                writer.PopIdent();
            }
 
            writer.WriteLine("}");
            writer.PopIdent();
            writer.WriteLine("})");
            return writer.Code;
        }
开发者ID:kumait,项目名称:HXF.net,代码行数:25,代码来源:AngularGenerator.cs


示例12: GenerateProperties

        /// <summary>
        /// Generates the properties.
        /// </summary>
        /// <param name='template'>
        /// if true it will generate only properties that are not included by default, because of the [generate=false] option.
        /// </param>
        static void GenerateProperties(ProtoMessage m, CodeWriter cw)
        {
            foreach (Field f in m.Fields.Values)
            {
                if (f.OptionExternal)
                    cw.WriteLine("//" + GenerateProperty(f) + " // Implemented by user elsewhere");
                else
                {
                    if (f.Comments != null)
                        cw.Summary(f.Comments);
                    cw.WriteLine(GenerateProperty(f));
                    cw.WriteLine();
                }

            }

            //Wire format field ID
            #if DEBUG
            cw.Comment("ProtocolBuffers wire field id");
            foreach (Field f in m.Fields.Values)
            {
                cw.WriteLine("public const int " + f.CsName + "FieldID = " + f.ID + ";");
            }
            #endif
        }
开发者ID:huodianyan,项目名称:ProtoBuf,代码行数:31,代码来源:MessageCode.cs


示例13: GenerateEnums

 static void GenerateEnums(ProtoMessage m, CodeWriter cw)
 {
     foreach (ProtoEnum me in m.Enums.Values)
     {
         GenerateEnum(me, cw);
     }
 }
开发者ID:huodianyan,项目名称:ProtoBuf,代码行数:7,代码来源:MessageCode.cs


示例14: WriteClass

        protected virtual void WriteClass(CodeWriter writer, Table table, Database schema, GenerationContext context)
        {
            writer.WriteLine();

            string entityBase = context.Parameters.EntityBase;
            if (string.IsNullOrEmpty(entityBase))
                entityBase = schema.EntityBase;

            var specifications = SpecificationDefinition.Partial;
            if (table.Type.AccessModifierSpecified)
                specifications |= GetSpecificationDefinition(table.Type.AccessModifier);
            else
                specifications |= SpecificationDefinition.Public;
            if (table.Type.ModifierSpecified)
                specifications |= GetSpecificationDefinition(table.Type.Modifier);

            var tableAttribute = NewAttributeDefinition<TableAttribute>();
            tableAttribute["Name"] = table.Name;
            using (writer.WriteAttribute(tableAttribute))
            using (writer.WriteClass(specifications,
                                     table.Type.Name, entityBase, context.Parameters.EntityInterfaces))
            {
                WriteClassHeader(writer, table, context);
                WriteCustomTypes(writer, table, schema, context);
                WriteClassExtensibilityDeclarations(writer, table, context);
                WriteClassProperties(writer, table, context);
                if (context.Parameters.GenerateEqualsHash)
                    WriteClassEqualsAndHash(writer, table, context);
                WriteClassChildren(writer, table, schema, context);
                WriteClassParents(writer, table, schema, context);
                WriteClassChildrenAttachment(writer, table, schema, context);
                WriteClassCtor(writer, table, schema, context);
            }
        }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:34,代码来源:CodeGenerator.Class.cs


示例15: 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


示例16: GenerateFileFooter

 private static void GenerateFileFooter(StreamWriter file, CodeWriter writer)
 {
     writer.Indent--;
     writer.WriteLine("}"); // end of test type
     writer.Indent--;
     writer.WriteLine("}"); // namesapce
     file.Close();
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:8,代码来源:Program.cs


示例17: Generate

 public override string Generate(Schema schema)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLine("----- TABLES -----");
     writer.Write(GenerateTables(schema));
     writer.WriteLine("----- STORED PROCEDURES -----");
     writer.Write(GenerateStoredProcedures(schema));
     return writer.Code;
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:9,代码来源:SqlServerDatabaseGenerator.cs


示例18: 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


示例19: WriteClasses

        protected virtual void WriteClasses(CodeWriter writer, Database schema, GenerationContext context)
        {
            IEnumerable<Table> tables = schema.Tables;

            var types = context.Parameters.GenerateTypes;
            if (types.Count > 0)
                tables = tables.Where(t => types.Contains(t.Type.Name));

            foreach (var table in tables)
                WriteClass(writer, table, schema, context);
        }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:11,代码来源:CodeGenerator.Class.cs


示例20: GenerateEnum

 public static void GenerateEnum(ProtoEnum me, CodeWriter cw)
 {
     cw.Bracket("public enum " + me.CsType);
     foreach (var epair in me.Enums)
     {
         cw.Summary(epair.Comment);
         cw.WriteLine(epair.Name + " = " + epair.Value + ",");
     }
     cw.EndBracket();
     cw.WriteLine();
 }
开发者ID:huodianyan,项目名称:ProtoBuf,代码行数:11,代码来源:MessageCode.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Codification类代码示例发布时间:2022-05-24
下一篇:
C# CodeTypeReference类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap