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


C# IndentedTextWriter.Flush方法代码示例

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


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

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

示例2: Serializes

 public void Serializes()
 {
     using (var sw = new StringWriter())
     using (var writer = new IndentedTextWriter(sw, "    "))
     {
       //  new KoSerializer(writer).Serialize("viewModel", new TestSemanticView());
         writer.Flush();
         Console.WriteLine(sw.GetStringBuilder().ToString());
     }
 }
开发者ID:Aethon,项目名称:odo,代码行数:10,代码来源:KoSerializerTests.cs

示例3: PrintUnityGameObject

		/// <summary>
		/// Prints a UnityEngine.GameObject, along with its components and children. Prints properties of components, but not of GameObjects, and doesn't print GameObjects in properties.
		/// </summary>
		/// <param name="o">The game object to print</param>
		/// <param name="componentFilter">A filter that says which components to print fully (printing their properties). By default, all will be expanded.</param>
		/// <param name="gameObjectFilter">A filter that says which GameObject children to print recursively (e.g. print their components and their children). Only the names of filtered children will appear.</param>
		/// <returns></returns>
		public static string PrintUnityGameObject(GameObject o, Func<GameObject, bool> gameObjectFilter = null, Func<Component, bool> componentFilter = null) {
			componentFilter = componentFilter ?? (x => true);
			gameObjectFilter = gameObjectFilter ?? (x => true);
			var dumper = new UnityObjectDumper();
			var strWriter = new StringWriter();
			var identedWriter = new IndentedTextWriter(strWriter, "\t");
			dumper.PrintUnityGameObject(o, identedWriter,gameObjectFilter, componentFilter);
			identedWriter.Flush();
			strWriter.Flush();
			return strWriter.ToString();
		}
开发者ID:RAlexander4287,项目名称:IEMod.pw,代码行数:18,代码来源:UnityObjectDumper.cs

示例4: ToCSharp

        public static string ToCSharp(this CodeCompileUnit unit)
        {
            using (var stream = new MemoryStream())
            {
                var csharp = new CSharpCodeProvider();

                var writer = new IndentedTextWriter(new StreamWriter(stream));
                csharp.GenerateCodeFromCompileUnit(unit, writer, new CodeGeneratorOptions());
                writer.Flush();

                return stream.ReadToEnd();
            }
        }
开发者ID:ByteCarrot,项目名称:Masslog,代码行数:13,代码来源:CodeCompileUnitExtensions.cs

示例5: CompileToCSharpSourceCode

        /// <summary>
        /// Converts a unit of CodeDOM code into the C# source equivalent
        /// </summary>
        public static string CompileToCSharpSourceCode(this CodeCompileUnit code)
        {
            var providerOptions = new Dictionary<string, string>();
            if (Environment.Version.Major < 4) providerOptions.Add("CompilerVersion", "v3.5");

            var compiler = new CSharpCodeProvider(providerOptions);
            string result;

            using (var sourceStream = new MemoryStream())
            {
                var tw = new IndentedTextWriter(new StreamWriter(sourceStream), "\t");

                compiler.GenerateCodeFromCompileUnit(code, tw, new CodeGeneratorOptions());

                tw.Flush();

                sourceStream.Seek(0, SeekOrigin.Begin);
                result = new StreamReader(sourceStream).ReadToEnd();
            }

            return result;
        }
开发者ID:BerserkerDotNet,项目名称:Synthesis,代码行数:25,代码来源:CodeDomUtility.cs

示例6: WriteClassFile

 /// <summary>
 /// Writes the class file.  This method actually creates the physical
 /// class file and populates it accordingly.
 /// </summary>
 /// <param name="className">Name of the class file to be written.</param>
 /// <param name="codenamespace">The <see cref="CodeNamespace"/> which represents the
 /// file to be written.</param>
 private void WriteClassFile(string className, CodeNamespace codenamespace)
 {
     var csharpCodeProvider = new CSharpCodeProvider();
     string sourceFile = this.OutputDirectory + this.buildSystem.DirectorySeparatorChar +
                         className + "." + csharpCodeProvider.FileExtension;
     sourceFile = Utility.ScrubPathOfIllegalCharacters(sourceFile);
     var indentedTextWriter =
         new IndentedTextWriter(this.buildSystem.GetTextWriter(sourceFile, false), "  ");
     var codeGenerationOptions = new CodeGeneratorOptions { BracingStyle = "C" };
     csharpCodeProvider.GenerateCodeFromNamespace(
         codenamespace,
         indentedTextWriter,
         codeGenerationOptions);
     indentedTextWriter.Flush();
     indentedTextWriter.Close();
 }
开发者ID:Jedzia,项目名称:NStub,代码行数:23,代码来源:CSharpCodeGenerator.cs

示例7: GenerateMainFile

        //      ADDED
        private void GenerateMainFile(IProject project, IComponentDescriptor cd)
        {
            string fname = MakeSysCSourceFileName("main");
            string path = project.AddFile(fname);
            StreamWriter sw = new StreamWriter(path);
            IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");
            string SimTimeUnit;

            CreateFileHeader(new GeneratorInfo(fname), tw);
            GenerateDependencies(null, tw, GetComponentName(cd));

            //  Get Simulation Time
            switch (SimTime.Unit)
            {
                case ETimeUnit.fs:
                    SimTimeUnit = "SC_FS";
                    break;
                case ETimeUnit.ps:
                    SimTimeUnit = "SC_PS";
                    break;
                case ETimeUnit.ns:
                    SimTimeUnit = "SC_NS";
                    break;
                case ETimeUnit.us:
                    SimTimeUnit = "SC_US";
                    break;
                case ETimeUnit.ms:
                    SimTimeUnit = "SC_MS";
                    break;
                case ETimeUnit.sec:
                    SimTimeUnit = "SC_SEC";
                    break;
                default:
                    throw new NotImplementedException();
            }

            tw.WriteLine();
            tw.WriteLine("int sc_main(int argc, char* argv[])");
            tw.WriteLine("{");
            tw.Indent++;
            tw.WriteLine("sc_report_handler::set_actions (SC_WARNING, SC_DO_NOTHING);");
            tw.WriteLine();
            tw.WriteLine(GetComponentName(cd) + " "
                + GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor)
                + "(\"" + GetComponentName(cd) + "\");");

            tw.WriteLine();
            tw.WriteLine("sc_start(" + SimTime.Value + ", " + SimTimeUnit + ");");
            tw.WriteLine();
            tw.WriteLine("return 0;");
            tw.Indent--;
            tw.WriteLine("}");

            tw.Flush();
            tw.Close();
            sw.Close();
        }
开发者ID:venusdharan,项目名称:systemsharp,代码行数:58,代码来源:SystemCGen.cs

示例8: GeneratePackage

        // TODO
        public void GeneratePackage(IProject project, PackageDescriptor pd)
        {
            string name = MakeIDName(pd.PackageName, pd);

            string fname = MakeSysCHeaderFileName(name);
            string path = project.AddFile(fname);
            project.AddFileAttribute(fname, pd);
            if (pd.Library != null)
                project.SetFileLibrary(fname, pd.Library);
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);
            IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");

            string cfname = MakeSysCSourceFileName(name);
            string path1 = project.AddFile(cfname);
            project.AddFileAttribute(cfname, pd);
            if (pd.Library != null)
                project.SetFileLibrary(cfname, pd.Library);
            MemoryStream ms1 = new MemoryStream();
            StreamWriter sw1 = new StreamWriter(ms1);
            IndentedTextWriter tw1 = new IndentedTextWriter(sw1, "  ");

            ClearDependencies();

            //tw.Indent++;
            tw1.WriteLine("#include \"" + fname + "\"");
            tw1.WriteLine();

            GenerateTypeDecls(pd, tw);

            foreach (MethodDescriptor md in pd.GetMethods())
            {
                GenerateMethodDecl(md, tw);
                tw.WriteLine();
                GenerateMethodImpl(md, tw1);
                tw1.WriteLine();
            }

            foreach (FieldDescriptor fd in pd.GetConstants())
            {
                DeclareField(fd, tw);
            }
            tw.Indent--;
            //tw.Indent++;
            tw.WriteLine("#endif");

            tw.Flush();
            sw = new StreamWriter(path);
            tw = new IndentedTextWriter(sw, "  ");

            tw1.Flush();
            sw1 = new StreamWriter(path1);
            tw1 = new IndentedTextWriter(sw1, "  ");

            CreateFileHeader(new GeneratorInfo(fname), tw);
            CreateFileHeader(new GeneratorInfo(cfname), tw1);
            GeneratePreProcDir(pd, tw);
            GenerateDependencies(pd, tw);
            //_extraLibraries.Add(new SysCLib(fname));

            tw.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            ms.CopyTo(sw.BaseStream);
            ms.Close();
            tw.Close();
            sw.Close();

            tw1.Flush();
            ms1.Seek(0, SeekOrigin.Begin);
            ms1.CopyTo(sw1.BaseStream);
            ms1.Close();
            tw1.Close();
            sw1.Close();

        }
开发者ID:venusdharan,项目名称:systemsharp,代码行数:76,代码来源:SystemCGen.cs

示例9: TouchEverything

		private void TouchEverything (IndentedTextWriter itw)
		{
			Assert.AreSame (writer.Encoding, itw.Encoding, "Encoding");
			Assert.AreEqual (0, itw.Indent, "Indent");
			itw.Indent = 1;
			Assert.AreSame (writer, itw.InnerWriter, "InnerWriter");
			Assert.AreEqual (writer.NewLine, itw.NewLine, "NewLine");

			itw.Write (true);
			itw.Write (Char.MinValue);
			itw.Write (Path.InvalidPathChars); // char[]
			itw.Write (Double.MinValue);
			itw.Write (Int32.MinValue);
			itw.Write (Int64.MaxValue);
			itw.Write (new object ());
			itw.Write (Single.MinValue);
			itw.Write (String.Empty);
			itw.Write ("{0}", String.Empty);
			itw.Write ("{0}{1}", Int32.MinValue, Int32.MaxValue);
			itw.Write ("{0}{1}{2}", Int32.MinValue, 0, Int32.MaxValue);
			itw.Write (Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
			itw.WriteLine ();
			itw.WriteLine (true);
			itw.WriteLine (Char.MinValue);
			itw.WriteLine (Path.InvalidPathChars); // char[]
			itw.WriteLine (Double.MinValue);
			itw.WriteLine (Int32.MinValue);
			itw.WriteLine (Int64.MaxValue);
			itw.WriteLine (new object ());
			itw.WriteLine (Single.MinValue);
			itw.WriteLine (String.Empty);
			itw.WriteLine (UInt32.MaxValue);
			itw.WriteLine ("{0}", String.Empty);
			itw.WriteLine ("{0}{1}", Int32.MinValue, Int32.MaxValue);
			itw.WriteLine ("{0}{1}{2}", Int32.MinValue, 0, Int32.MaxValue);
			itw.WriteLine (Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
			itw.WriteLineNoTabs (String.Empty);
			itw.Flush ();
			itw.Close ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:40,代码来源:IndentedTextWriterCas.cs

示例10: WriteInventoryToFile

        private static void WriteInventoryToFile(string fileName, ItemStacks slots)
        {
            Log.Info($"Writing inventory to filename: {fileName}");
            FileStream file = File.OpenWrite(fileName);

            IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(file));

            writer.WriteLine("// GENERATED CODE. DON'T EDIT BY HAND");
            writer.Indent++;
            writer.Indent++;
            writer.WriteLine("public static List<Item> CreativeInventoryItems = new List<Item>()");
            writer.WriteLine("{");
            writer.Indent++;

            foreach (var entry in slots)
            {
                var slot = entry;
                NbtCompound extraData = slot.ExtraData;
                if (extraData == null)
                {
                    writer.WriteLine($"new Item({slot.Id}, {slot.Metadata}, {slot.Count}),");
                }
                else
                {
                    NbtList ench = (NbtList) extraData["ench"];
                    NbtCompound enchComp = (NbtCompound) ench[0];
                    var id = enchComp["id"].ShortValue;
                    var lvl = enchComp["lvl"].ShortValue;
                    writer.WriteLine($"new Item({slot.Id}, {slot.Metadata}, {slot.Count}){{ExtraData = new NbtCompound {{new NbtList(\"ench\") {{new NbtCompound {{new NbtShort(\"id\", {id}), new NbtShort(\"lvl\", {lvl}) }} }} }} }},");
                }
            }

            // Template
            new ItemAir {ExtraData = new NbtCompound {new NbtList("ench") {new NbtCompound {new NbtShort("id", 0), new NbtShort("lvl", 0)}}}};
            //var compound = new NbtCompound(string.Empty) { new NbtList("ench", new NbtCompound()) {new NbtShort("id", 0),new NbtShort("lvl", 0),}, };

            writer.Indent--;
            writer.WriteLine("};");
            writer.Indent--;
            writer.Indent--;

            writer.Flush();
            file.Close();
        }
开发者ID:andrewhutche,项目名称:MiNET,代码行数:44,代码来源:MiNetClient.cs

示例11: WriteDatabaseProject

		private void WriteDatabaseProject(SolutionNode solution, DatabaseProjectNode project)
		{
			string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "dbp");
			IndentedTextWriter ps = new IndentedTextWriter(new StreamWriter(projectFile), "   ");

			kernel.CurrentWorkingDirectory.Push();

			Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));

			using (ps)
			{
				ps.WriteLine("# Microsoft Developer Studio Project File - Database Project");
				ps.WriteLine("Begin DataProject = \"{0}\"", project.Name);
				ps.Indent++;
				ps.WriteLine("MSDTVersion = \"80\"");
				// TODO: Use the project.Files property
				if (ContainsSqlFiles(Path.GetDirectoryName(projectFile)))
					WriteDatabaseFoldersAndFiles(ps, Path.GetDirectoryName(projectFile));

				ps.WriteLine("Begin DBRefFolder = \"Database References\"");
				ps.Indent++;
				foreach (DatabaseReferenceNode reference in project.References)
				{
					ps.WriteLine("Begin DBRefNode = \"{0}\"", reference.Name);
					ps.Indent++;
					ps.WriteLine("ConnectStr = \"{0}\"", reference.ConnectionString);
					ps.WriteLine("Provider = \"{0}\"", reference.ProviderId.ToString("B").ToUpper());
					//ps.WriteLine("Colorizer = 5");
					ps.Indent--;
					ps.WriteLine("End");
				}
				ps.Indent--;
				ps.WriteLine("End");
				ps.Indent--;
				ps.WriteLine("End");

				ps.Flush();
			}

			kernel.CurrentWorkingDirectory.Pop();
		}
开发者ID:RavenB,项目名称:gridsearch,代码行数:41,代码来源:VSGenericTarget.cs

示例12: ToString

		/// <summary>
		/// Retorna a representação string da consulta SQL.
		/// </summary>
		/// <returns>A representação string da consulta SQL.</returns>
		public override string ToString()
		{
			var sb = new StringBuilder();

			using (var sw = new StringWriter(sb))
			using (var tw = new IndentedTextWriter(sw))
			{
				Render(tw);
				tw.Flush();
			}

			return sb.ToString();
		}
开发者ID:elementar,项目名称:Suprifattus.Util,代码行数:17,代码来源:SqlQuery.cs

示例13: PrintException

		public static string PrintException(Exception ex) {
			var strWriter = new StringWriter();
			var indentedWriter = new IndentedTextWriter(strWriter);
			PrintExceptionWithoutTrace(indentedWriter, ex);
			indentedWriter.WriteLine("Unity Stack Trace:");
			indentedWriter.Indent++;
			var traceLines = StackTraceUtility.ExtractStringFromException(ex).Split(new[] {
				"\r",
				"\n"
			}, StringSplitOptions.RemoveEmptyEntries);
			traceLines.ToList().ForEach(indentedWriter.WriteLine);
			indentedWriter.Flush();
			strWriter.Flush();
			return strWriter.ToString();
		}
开发者ID:Bigtuna00,项目名称:IEMod.pw,代码行数:15,代码来源:IEDebug.cs

示例14: WriteClassFile

 /// <summary>
 /// Writes the class file.  This method actually creates the physical
 /// class file and populates it accordingly.
 /// </summary>
 /// <param name="className">Name of the class file to be written.</param>
 /// <param name="codeNamespace">The CodeNamespace which represents the
 /// file to be written.</param>
 private void WriteClassFile(string className, CodeNamespace codeNamespace)
 {
     CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider();
     string sourceFile = _outputDirectory + Path.DirectorySeparatorChar +
         className + "." + cSharpCodeProvider.FileExtension;
     sourceFile = Utility.ScrubPathOfIllegalCharacters(sourceFile);
     IndentedTextWriter indentedTextWriter =
         new IndentedTextWriter(new StreamWriter(sourceFile, false), "  ");
     CodeGeneratorOptions codeGenerationOptions = new CodeGeneratorOptions();
     codeGenerationOptions.BracingStyle = "C";
     cSharpCodeProvider.GenerateCodeFromNamespace(codeNamespace, indentedTextWriter,
         codeGenerationOptions);
     indentedTextWriter.Flush();
     indentedTextWriter.Close();
 }
开发者ID:jeremyjarrell,项目名称:NStub,代码行数:22,代码来源:CSharpCodeGenerator.cs

示例15: GenerateCode

        /// <summary>
        /// Compiles the code within this object into the selected code format and saves it to the given file name.
        /// </summary>
        /// <returns>A FileInfo object set to point to the source file created.</returns>
        public FileInfo GenerateCode(string FileName)
        {
            // First, we're going to set the source FileInfo object to the next source file.
            fiSrc = new FileInfo(FileName);

            // Then, we check for an extension on that file and strip it if one was passed.
            #region DEBUG Output
#if DEBUG
            Console.Write(fiSrc.Extension);
#endif
            #endregion
            if (fiSrc.Extension.Length > 0 && fiSrc.Name.Length > fiSrc.Extension.Length)
                FileName = fiSrc.FullName.Substring(0, fiSrc.FullName.Length - fiSrc.Extension.Length);

            // We get the default extension from the provider object.  Some provider types do not supply the
            //   period on the extension, so we have to check for that.
            if (provider.FileExtension[0] == '.')
                FileName = FileName + provider.FileExtension;
            else
                FileName = FileName + "." + provider.FileExtension;

            IndentedTextWriter tw = null;
            try
            {
                // Now we create the text writer object.  We use an 'IndentedTextWriter' here to achieve
                //   more human-readable source code.
                tw = new IndentedTextWriter(new StreamWriter(FileName, false), "   ");

                // We need to reset our FileInfo object in case the filename was changed.
                fiSrc = new FileInfo(FileName);

                // Now we use the provider object to generate the source code.
                #region DEBUG Output
#if DEBUG
                for (int i = 0; i < compileUnit.Namespaces.Count; i++)
                {
                    Console.WriteLine("\nNamespace: {0}\n\nImports:\n", compileUnit.Namespaces[0].Name);
                    for (int t = 0; t < compileUnit.Namespaces[i].Imports.Count; t++)
                    {
                        Console.WriteLine("  using {0}", compileUnit.Namespaces[i].Imports[t].Namespace);
                    }
                    Console.WriteLine("\n\nClasses:\n");
                    for (int t = 0; t < compileUnit.Namespaces[i].Types.Count; t++)
                    {
                        Console.WriteLine("  -={0} {1}=-", compileUnit.Namespaces[i].Types[t].Attributes.ToString(), compileUnit.Namespaces[i].Types[t].Name);
                        for (int x = 0; x < compileUnit.Namespaces[i].Types[t].Members.Count; x++)
                        {
                            Console.WriteLine("      {0} {1}(-{2}-)", compileUnit.Namespaces[i].Types[t].Members[x].Attributes.ToString(), compileUnit.Namespaces[i].Types[t].Members[x].Name, compileUnit.Namespaces[i].Types[t].Members[x].LinePragma);
                            Console.WriteLine(compileUnit.Namespaces[i].Types[t].Members[x].ToString());
                            for (int j = 0; j < compileUnit.Namespaces[i].Types[t].Members[x].Comments.Count; j++)
                                Console.WriteLine(compileUnit.Namespaces[i].Types[t].Members[x].Comments[j].Comment.Text);
                        }
                    }
                }
#endif
                #endregion
                provider.GenerateCodeFromCompileUnit(compileUnit, tw, new CodeGeneratorOptions());
            }
            catch
            { throw; }
            finally
            {
                // Can't forget to flush and close the output file.  Otherwise, any other functions that
                //   attempt to access it will cause an IO exception.
                if (tw != null)
                {
                    tw.Flush();
                    tw.Close();
                }
            }

            // Return the FileInfo object configured for the output file.
            return fiSrc;
        }
开发者ID:tenshino,项目名称:RainstormStudios,代码行数:78,代码来源:DynaCode.cs


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