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


C# IndentedTextWriter.Close方法代码示例

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


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

示例1: Run

        public void Run()
        {
            var compileUnit = new CodeCompileUnit();
            var myNamespace = new CodeNamespace("MyNamespace");
            myNamespace.Imports.Add(new CodeNamespaceImport("System"));
            var myClass = new CodeTypeDeclaration("MyClass");
            var start = new CodeEntryPointMethod();
            var cs1 = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Console"),
                "WriteLine", new CodePrimitiveExpression("Hello World!"));

            compileUnit.Namespaces.Add(myNamespace);
            myNamespace.Types.Add(myClass);
            myClass.Members.Add(start);
            start.Statements.Add(cs1);

            var provider = new CSharpCodeProvider();

            using (var sw = new StreamWriter("HelloWorld.cs", false))
            {
                var tw = new IndentedTextWriter(sw, "    ");
                provider.GenerateCodeFromCompileUnit(compileUnit, tw,
                    new CodeGeneratorOptions());
                tw.Close();
            }
        }
开发者ID:rrsc,项目名称:ProgrammingInCSharp,代码行数:26,代码来源:GeneratingASourceFileFromCodeCompileUnit.cs

示例2: ParseToCode

 public GeneratorResults ParseToCode(string TemplateCode, string defaultnamespace, string defaultclassname, string baseClassFullName)
 {
     GeneratorResults razorResults;
     var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
     host.DefaultBaseClass = baseClassFullName;//typeof(BulaqTemplateForRazorBase).FullName;
     host.DefaultNamespace = defaultnamespace;
     host.DefaultClassName = defaultclassname;
     host.NamespaceImports.Add("System");
     host.NamespaceImports.Add("BulaqCMS.Models");
     host.GeneratedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral");
     var engine = new RazorTemplateEngine(host);
     using (var reader = new StringReader(TemplateCode))
     {
         razorResults = engine.GenerateCode(reader);
         CSharpCodeProvider codeProvider = new CSharpCodeProvider();
         CodeGeneratorOptions options = new CodeGeneratorOptions();
         options.BracingStyle = "C";
         using (StringWriter writer = new StringWriter())
         {
             IndentedTextWriter indentwriter = new IndentedTextWriter(writer, "    ");
             codeProvider.GenerateCodeFromCompileUnit(razorResults.GeneratedCode, indentwriter, options);
             indentwriter.Flush();
             indentwriter.Close();
             LastGeneratedCode = writer.GetStringBuilder().ToString();
             string codePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\code.cs";
             File.WriteAllText(codePath, LastGeneratedCode, Encoding.UTF8);
         }
     }
     return razorResults;
 }
开发者ID:abduwaris,项目名称:BulaqCMS,代码行数:30,代码来源:RazorTemplateParser.cs

示例3: WriteMigrationFile

        public void WriteMigrationFile()
        {
            // check if migration context base class exists
            string context = String.Format("{0}\\{1}.cs", Globals.Settings.Paths.Migration,
                Globals.Settings.Names.MigrationContext);
            if (!File.Exists(context))
            {
                WriteMigrationContextFile();
            }

            string migrationClass = String.Format(migrationName, Globals.Settings.Names.Database);

            string path = String.Format("{0}\\{1}.cs", Globals.Settings.Paths.Migration, Migration.ClassFile);

            var template = Activator.CreateInstance<DatabaseMigrationTemplate>();
            var session = new TextTemplatingSession();
            // add variables
            session["migrationClass"] = Migration.ClassFile;
            session["namespce"] = Globals.Settings.Namespaces.Migration;
            session["databaseName"] = Globals.Settings.Names.Database;
            session["connection"] = Globals.BasicConnectionString;
            template.Session = session;
            template.Initialize();
            // generate the source file
            string source = template.TransformText();
            // Create a StreamWriter to the output file.
            using (StreamWriter sw = new StreamWriter(path, false))
            {
                IndentedTextWriter writer = new IndentedTextWriter(sw);
                writer.Write(source);
                writer.Close();
            }
        }
开发者ID:petegleeson,项目名称:Cake,代码行数:33,代码来源:DatabaseOperation.cs

示例4: Main

        static void Main(string[] args)
        {
            CodeCompileUnit compileUnit = new CodeCompileUnit();
            CodeNamespace myNamespace = new CodeNamespace("MyNamespace");
            myNamespace.Imports.Add(new CodeNamespaceImport("System"));
            CodeTypeDeclaration myClass = new CodeTypeDeclaration("MyClass");
            CodeEntryPointMethod start = new CodeEntryPointMethod();
            CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("Console"), "WriteLine", new CodePrimitiveExpression("Hello World"));
            compileUnit.Namespaces.Add(myNamespace);
            myNamespace.Types.Add(myClass);
            myClass.Members.Add(start);
            start.Statements.Add(cs1);

            CSharpCodeProvider provider = new CSharpCodeProvider();

            using(StreamWriter sw = new StreamWriter("HelloWorld.cs", false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, " ");
                provider.GenerateCodeFromCompileUnit(compileUnit, tw, new CodeGeneratorOptions());
                tw.Close();
            }

            Console.WriteLine("HelloWorld.cs generated in .../bin/Debug or .../bin/Release project folders.");

            Console.Write("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:27,代码来源:Program.cs

示例5: CreateOutput

        public override string CreateOutput()
        {
            RemoveComments = Generators.Any(p => !p.AlwaysRegenerate);

            Namespace = new CodeNamespace(NamespaceName);
            Unit = new CodeCompileUnit();
            Unit.Namespaces.Add(Namespace);
      
            foreach (var codeGenerator in Generators.Where(p=>p.IsValid()))
            {
               // UnityEngine.Debug.Log(codeGenerator.GetType().Name + " is generating");
                codeGenerator.Initialize(this);
            }
            var provider = new CSharpCodeProvider();

            var sb = new StringBuilder();
            var tw1 = new IndentedTextWriter(new StringWriter(sb), "    ");
            provider.GenerateCodeFromCompileUnit(Unit, tw1, new CodeGeneratorOptions());
            tw1.Close();
            if (RemoveComments)
            {
                var removedLines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Skip(10).ToArray();
                return string.Join(Environment.NewLine, removedLines);
            }
            return sb.ToString();
        }
开发者ID:InvertGames,项目名称:uFrame.Editor,代码行数:26,代码来源:CodeFileGenerator.cs

示例6: GenerateCSharpCode

        public static String GenerateCSharpCode(CodeCompileUnit compileunit)
        {
            // Generate the code with the C# code provider.
            CSharpCodeProvider provider = new CSharpCodeProvider();

            // Build the output file name.
            String sourceFile;
            if (provider.FileExtension[0] == '.')
            {
                sourceFile = "HelloWorld" + provider.FileExtension;
            }
            else
            {
                sourceFile = "HelloWorld." + provider.FileExtension;
            }

            // Create a TextWriter to a StreamWriter to the output file.
            IndentedTextWriter tw = new IndentedTextWriter(
                    new StreamWriter(sourceFile, false), "    ");

            // Generate source code using the code provider.
            provider.GenerateCodeFromCompileUnit(compileunit, tw,
                    new CodeGeneratorOptions());

            // Close the output file.
            tw.Close();

            return sourceFile;
        }
开发者ID:nyet,项目名称:nyet,代码行数:29,代码来源:Program.cs

示例7: GenerateSource

        internal string GenerateSource(CodeDomProvider codeProvider)
        {
            StringBuilder sb = new StringBuilder();
            TextWriter tWriter = new IndentedTextWriter(new StringWriter(sb));
            CodeCompileUnit ccu = GenerateCode();
            codeProvider.GenerateCodeFromCompileUnit(ccu, tWriter, new CodeGeneratorOptions());
            codeProvider.Dispose();

            tWriter.Close();

            return sb.ToString();
        }
开发者ID:jwebber974,项目名称:NumberPrinter,代码行数:12,代码来源:CodeDomExpressionVisitor.cs

示例8: Main

        public static void Main()
        {
            CSharpCodeProvider cs = new CSharpCodeProvider();

            CodeGenerator cg = new CodeGenerator();
            using (StreamWriter sw=new StreamWriter("HelloWorld.cs",false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "      ");
                cs.GenerateCodeFromCompileUnit(cg.GetCompierUnit(), tw, new CodeGeneratorOptions());
                tw.Close();
            }
        }
开发者ID:vijaychandar1989,项目名称:70-483_Samples,代码行数:12,代码来源:CodeGeneratorCS.cs

示例9: GenerateFile

        private void GenerateFile()
        {
            CSharpCodeProvider provider = new CSharpCodeProvider();

            using (StreamWriter sw = new StreamWriter("HelloWorld.cs", false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, " ");
                provider.GenerateCodeFromCompileUnit(GenerateHelloWorldCode(), tw, new CodeGeneratorOptions());
                tw.Close();

            }
        }
开发者ID:mayankaggarwal,项目名称:MyConcepts,代码行数:12,代码来源:CodeGenerationExamples.cs

示例10: Main

        static void Main(string[] args)
        {
            CodeCompileUnit ccu = HelloWorldCodeDOM();

            CSharpCodeProvider provider = new CSharpCodeProvider();

            using(StreamWriter sw = new StreamWriter("HelloWorld.cs", false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "    ");
                provider.GenerateCodeFromCompileUnit(ccu, tw, new CodeGeneratorOptions());
                tw.Close();
            }
        }
开发者ID:jbijoux,项目名称:Exam-70-483,代码行数:13,代码来源:Program.cs

示例11: GenerateCodeUsingCodeDOM

 private void GenerateCodeUsingCodeDOM(CodeCompileUnit codeCompileUnit, string outputFile)
 {
     var options = new CodeGeneratorOptions
     {
         BracingStyle = "JS"
     };
     var codeDomProvider = new TypescriptCodeProvider();
     using (var textWriter = new IndentedTextWriter(new StreamWriter(outputFile)))
     {
         codeDomProvider.GenerateCodeFromCompileUnit(codeCompileUnit, textWriter, options);
         textWriter.Close();
     }
 }
开发者ID:mredbishop,项目名称:WSDLToTypescriptProxyGenerator,代码行数:13,代码来源:TypescriptCodeCreator.cs

示例12: GenerateClass

        public void GenerateClass()
        {
            IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(this.fileName));

            Console.WriteLine("Generating " + this.fileName);

            WriteFileHeader(writer);

            foreach (Stanza stanza in SyntaxInfo.Instance)
            {
                stanza.Generate(writer, this.className, isStatic);
            }

            WriteFileTrailer(writer);

            writer.Close();
        }
开发者ID:Vernathic,项目名称:ic-AutoTest.NET4CTDD,代码行数:17,代码来源:CodeGenerator.cs

示例13: BuildAssembly

        public Assembly BuildAssembly()
        {
            GetReferencedTypes().ForEach(AddAssemblyReference);

            CSharpCodeProvider provider =
              new CSharpCodeProvider();
            ICodeCompiler compiler = provider.CreateCompiler();
            CompilerResults results =
               compiler.CompileAssemblyFromDom(CompilerParameters, this);
            if (results.Errors.HasErrors)
            {
                StringBuilder errors = new StringBuilder("Compiler Errors :\r\n");
                foreach (CompilerError error in results.Errors)
                {
                    errors.AppendFormat("Line {0},{1}\t: {2}\n",
                           error.Line, error.Column, error.ErrorText);
                }
                var buffer = new StringBuilder();
                using(var writer = new StringWriter(buffer))
                {
                    using (var textWriter = new IndentedTextWriter(writer))
                    {
                        provider.GenerateCodeFromCompileUnit(this, textWriter, new CodeGeneratorOptions());
                        textWriter.Close();
                    }
                }

                var source = new StringBuilder();
                var lines = buffer.ToString().Split(new string[] {Environment.NewLine}, StringSplitOptions.None);
                for(int i = 0; i < lines.Length; i++)
                {
                    source.AppendLine(i + lines[i]);
                }
                throw new Exception(
                    errors.ToString()
                    + Environment.NewLine
                    + Environment.NewLine
                    + "CODE:"
                    + Environment.NewLine
                    + source);
            }

            return results.CompiledAssembly;
        }
开发者ID:croweman,项目名称:Refraction,代码行数:44,代码来源:AssemblyDefinition.cs

示例14: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            CSharpCodeProvider provider = new CSharpCodeProvider();

            using (StreamWriter sw = new StreamWriter("HelloWorld.cs", false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "   ");
                provider.GenerateCodeFromCompileUnit(GetCode(), tw, new CodeGeneratorOptions());
                tw.Close();
            }

            Func<int, int, int> addFunc = (x, y) => x + y;
            Console.WriteLine(addFunc(2, 3));

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
开发者ID:vmp,项目名称:CSharpExamples,代码行数:19,代码来源:Program.cs

示例15: Generate

        public void Generate(CodeCompileUnit targetUnit)
        {
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
            CodeGeneratorOptions options = new CodeGeneratorOptions();
            options.BracingStyle = "C";
            options.IndentString = "    ";
            options.BlankLinesBetweenMembers = true;

            if (Directory.Exists(destinationPath) && ConfigurationApp.GetProperty("IsGeneratedSolutionDirectoryPurged") != "true")
            {
                Directory.Delete(destinationPath, true);
                ConfigurationApp.SaveProperty("IsGeneratedSolutionDirectoryPurged", "true");
            }
            Directory.CreateDirectory(destinationPath);
            // Build the output file name.
            foreach (CodeNamespace namespaceUnit in targetUnit.Namespaces)
            {
                var namespaceName = namespaceUnit.Name;

                string sourceFile;
                if (provider.FileExtension[0] == '.')
                {
                    sourceFile = this.PathFromNamespace(destinationPath, namespaceName) + "/" + namespaceUnit.Types[0].Name + provider.FileExtension;
                }
                else
                {
                    sourceFile = this.PathFromNamespace(destinationPath, namespaceName) + "/" + namespaceUnit.Types[0].Name + "." + provider.FileExtension;
                }

                using (StreamWriter sw = new StreamWriter(sourceFile, false))
                {
                    IndentedTextWriter tw = new IndentedTextWriter(sw, "    ");
                    provider.GenerateCodeFromNamespace(namespaceUnit, tw, options);
                    tw.Close();
                }

                Console.WriteLine(sourceFile + " has been generated");
            }
        }
开发者ID:swoog,项目名称:EaiConverter,代码行数:39,代码来源:CsharpSourceCodeGeneratorService.cs


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