C# StreamWriter.ToString的代码示例

通过代码示例来学习C# StreamWriter.ToString方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


StreamWriter.ToString是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamWriter.ToString() 已经帮大家高亮显示了,大家可以重点学习StreamWriter.ToString() 方法的写法,从而快速掌握该方法的应用。

StreamWriter.ToString的代码示例1 - RunCommandWithWaitAndStdIn()

    using System.IO;

        /// 
        /// Run the specified command as an external program. This method will return once the GVFSLock has been acquired.
        /// 
        /// The ID of the process that acquired the lock.
        ///  that can be signaled to exit the lock acquisition program.
        private static ManualResetEventSlim RunCommandWithWaitAndStdIn(
            GVFSFunctionalTestEnlistment enlistment,
            int resetTimeout,
            string pathToCommand,
            string args,
            string lockingProcessCommandName,
            string stdinToQuit,
            out int processId)
        {
            ManualResetEventSlim resetEvent = new ManualResetEventSlim(initialState: false);

            ProcessStartInfo processInfo = new ProcessStartInfo(pathToCommand);
            processInfo.WorkingDirectory = enlistment.RepoRoot;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardInput = true;
            processInfo.Arguments = args;

            Process holdingProcess = Process.Start(processInfo);
            StreamWriter stdin = holdingProcess.StandardInput;
            processId = holdingProcess.Id;

            enlistment.WaitForLock(lockingProcessCommandName);

            Task.Run(
                () =>
                {
                    resetEvent.Wait(resetTimeout);

                    try
                    {
                        // Make sure to let the holding process end.
                        if (stdin != null)
                        {
                            stdin.WriteLine(stdinToQuit);
                            stdin.Close();
                        }

                        if (holdingProcess != null)
                        {
                            bool holdingProcessHasExited = holdingProcess.WaitForExit(10000);

                            if (!holdingProcess.HasExited)
                            {
                                holdingProcess.Kill();
                            }

                            holdingProcess.Dispose();

                            holdingProcessHasExited.ShouldBeTrue("Locking process did not exit in time.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Assert.Fail($"{nameof(RunCommandWithWaitAndStdIn)} exception closing stdin {ex.ToString()}");
                    }
                    finally
                    {
                        resetEvent.Set();
                    }
                });

            return resetEvent;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:72,代码来源:GitHelpers.cs

在RunCommandWithWaitAndStdIn()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例2 - InvokeGitImpl()

    using System.IO;

        protected virtual Result InvokeGitImpl(
            string command,
            string workingDirectory,
            string dotGitDirectory,
            bool useReadObjectHook,
            Action writeStdIn,
            Action parseStdOutLine,
            int timeoutMs,
            string gitObjectsDirectory = null)
        {
            if (failedToSetEncoding && writeStdIn != null)
            {
                return new Result(string.Empty, "Attempting to use to stdin, but the process does not have the right input encodings set.", Result.GenericFailureCode);
            }

            try
            {
                // From https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
                // To avoid deadlocks, use asynchronous read operations on at least one of the streams.
                // Do not perform a synchronous read to the end of both redirected streams.
                using (this.executingProcess = this.GetGitProcess(command, workingDirectory, dotGitDirectory, useReadObjectHook, redirectStandardError: true, gitObjectsDirectory: gitObjectsDirectory))
                {
                    StringBuilder output = new StringBuilder();
                    StringBuilder errors = new StringBuilder();

                    this.executingProcess.ErrorDataReceived += (sender, args) =>
                    {
                        if (args.Data != null)
                        {
                            errors.Append(args.Data + "\n");
                        }
                    };
                    this.executingProcess.OutputDataReceived += (sender, args) =>
                    {
                        if (args.Data != null)
                        {
                            if (parseStdOutLine != null)
                            {
                                parseStdOutLine(args.Data);
                            }
                            else
                            {
                                output.Append(args.Data + "\n");
                            }
                        }
                    };

                    lock (this.executionLock)
                    {
                        lock (this.processLock)
                        {
                            if (this.stopping)
                            {
                                return new Result(string.Empty, nameof(GitProcess) + " is stopping", Result.GenericFailureCode);
                            }

                            this.executingProcess.Start();

                            if (this.LowerPriority)
                            {
                                try
                                {
                                    this.executingProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
                                }
                                catch (InvalidOperationException)
                                {
                                    // This is thrown if the process completes before we can set its priority.
                                }
                            }
                        }

                        writeStdIn?.Invoke(this.executingProcess.StandardInput);
                        this.executingProcess.StandardInput.Close();

                        this.executingProcess.BeginOutputReadLine();
                        this.executingProcess.BeginErrorReadLine();

                        if (!this.executingProcess.WaitForExit(timeoutMs))
                        {
                            this.executingProcess.Kill();

                            return new Result(output.ToString(), "Operation timed out: " + errors.ToString(), Result.GenericFailureCode);
                        }
                    }

                    return new Result(output.ToString(), errors.ToString(), this.executingProcess.ExitCode);
                }
            }
            catch (Win32Exception e)
            {
                return new Result(string.Empty, e.Message, Result.GenericFailureCode);
            }
            finally
            {
                this.executingProcess = null;
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:99,代码来源:GitProcess.cs

在InvokeGitImpl()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例3 - BuildWxs()

    using System.IO;

        /// 
        /// Builds the WiX source file (*.wxs) from the specified  instance.
        /// 
        /// The project.
        /// 
        public static string BuildWxs(Bundle project)
        {
            lock (typeof(Compiler))
            {
                if (Compiler.ClientAssembly.IsEmpty())
                    Compiler.ClientAssembly = Compiler.FindClientAssemblyInCallStack();

                project.Validate();

                lock (Compiler.AutoGeneration.WxsGenerationSynchObject)
                {
                    var oldAlgorithm = AutoGeneration.CustomIdAlgorithm;
                    try
                    {
                        project.ResetAutoIdGeneration(supressWarning: false);

                        AutoGeneration.CustomIdAlgorithm = project.CustomIdAlgorithm ?? AutoGeneration.CustomIdAlgorithm;

                        string file = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, project.OutFileName) + ".wxs");

                        if (IO.File.Exists(file))
                            IO.File.Delete(file);

                        string extraNamespaces = project.WixNamespaces.Distinct()
                                                                      .Select(x => x.StartsWith("xmlns:") ? x : "xmlns:" + x)
                                                                      .ConcatItems(" ");

                        var wix3Namespace = "http://schemas.microsoft.com/wix/2006/wi";
                        var wix4Namespace = "http://wixtoolset.org/schemas/v4/wxs";

                        var wixNamespace = Compiler.IsWix4 ? wix4Namespace : wix3Namespace;

                        var doc = XDocument.Parse(
                            @"
                             " + $"
                             ");

                        doc.Root.Add(project.ToXml());

                        AutoElements.NormalizeFilePaths(doc, project.SourceBaseDir, EmitRelativePaths);

                        project.InvokeWixSourceGenerated(doc);

                        AutoElements.ExpandCustomAttributes(doc, project);

                        if (WixSourceGenerated != null)
                            WixSourceGenerated(doc);

                        var xmlEncoding = Encoding.UTF8;

                        string xml = "";
                        using (IO.StringWriter sw = new StringWriterWithEncoding(xmlEncoding))
                        {
                            doc.Save(sw, SaveOptions.None);
                            xml = sw.ToString();
                        }

                        //of course you can use XmlTextWriter.WriteRaw but this is just a temporary quick'n'dirty solution
                        //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2657663&SiteID=1
                        xml = xml.Replace("xmlns=\"\"", "");

                        DefaultWixSourceFormatedHandler(ref xml);

                        project.InvokeWixSourceFormated(ref xml);
                        if (WixSourceFormated != null)
                            WixSourceFormated(ref xml);

                        using (var sw = new IO.StreamWriter(file, false, xmlEncoding))
                            sw.WriteLine(xml);

                        Compiler.OutputWriteLine("\n----------------------------------------------------------\n");
                        Compiler.OutputWriteLine("Wix project file has been built: " + file + "\n");

                        project.InvokeWixSourceSaved(file);
                        if (WixSourceSaved != null)
                            WixSourceSaved(file);

                        return file;
                    }
                    finally
                    {
                        AutoGeneration.CustomIdAlgorithm = oldAlgorithm;
                        project.ResetAutoIdGeneration(supressWarning: true);
                    }
                }
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:94,代码来源:Compiler.Bootstrapper.cs

在BuildWxs()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例4 - WriteInverseBindMatricesToStream()

    using System.IO;

        private void WriteInverseBindMatricesToStream(Mesh mesh, StreamWriter writer)
        {
            writer.WriteLine($"      ");
            writer.WriteLine($"      ");

            foreach (Bone bone in mesh.Bones)
            {
                Matrix4x4 ibm = bone.OffsetMatrix;
                ibm.Transpose();

                writer.WriteLine($"       {ibm.A1.ToString("F")} {ibm.A2.ToString("F")} {ibm.A3.ToString("F")} {ibm.A4.ToString("F")}");
                writer.WriteLine($"       {ibm.B1.ToString("F")} {ibm.B2.ToString("F")} {ibm.B3.ToString("F")} {ibm.B4.ToString("F")}");
                writer.WriteLine($"       {ibm.C1.ToString("F")} {ibm.C2.ToString("F")} {ibm.C3.ToString("F")} {ibm.C4.ToString("F")}");
                writer.WriteLine($"       {ibm.D1.ToString("F")} {ibm.D2.ToString("F")} {ibm.D3.ToString("F")} {ibm.D4.ToString("F")}");

                if (bone != mesh.Bones.Last())
                    writer.WriteLine("");
            }

            writer.WriteLine("      ");
            writer.Flush();

            writer.WriteLine("      ");
            writer.WriteLine($"       ");
            writer.WriteLine("         ");
            writer.WriteLine("       ");
            writer.WriteLine("      ");
            writer.WriteLine("      ");
            writer.Flush();
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:32,代码来源:AssimpSaver.cs

在WriteInverseBindMatricesToStream()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了16次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例5 - DownloadRelease()

    using System.IO;
        static bool DownloadRelease(string downloadName, string url, string ProgramVersion, string CompileDate, string CommitInfo)
        {
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.DownloadFile(url, downloadName + ".zip");
                }
                if (Directory.Exists(downloadName + "/"))
                    Directory.Delete(downloadName + "/", true);
                ZipFile.ExtractToDirectory(downloadName + ".zip", downloadName + "/");

                //Zip not needed anymore
                File.Delete(downloadName + ".zip");
                string versionTxt = Path.Combine(Path.GetFullPath(downloadName + "/"), "Version.txt");

                using (StreamWriter writer = new StreamWriter(versionTxt))
                {
                    writer.WriteLine($"{ProgramVersion}");
                    writer.WriteLine($"{CompileDate}");
                    writer.WriteLine($"{CommitInfo}");
                }
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to download update! {ex.ToString()}");
                return false;
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:31,代码来源:Program.cs

在DownloadRelease()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例6 - ToTextAll()

    using System.IO;

        public static string ToTextAll(IEnumerable records, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
            where TRec : class
        {
            if (records == null) return null;

            if (typeof(DataTable).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder csv = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                    using (var w = new ChoCSVWriter(csv, configuration))
                        w.Write(dt);
                }

                return csv.ToString();
            }
            else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder csv = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                    using (var w = new ChoCSVWriter(csv, configuration))
                        w.Write(dt);
                }

                return csv.ToString();
            }

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoCSVWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                parser.Write(records);

                writer.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:47,代码来源:ChoCSVWriter.cs

在ToTextAll()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例7 - ToTextAll()

    using System.IO;

        public static string ToTextAll(IEnumerable records, ChoFixedLengthRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
            where TRec : class
        {
            if (records == null) return null;

            if (typeof(DataTable).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder text = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                    using (var w = new ChoFixedLengthWriter(text, configuration))
                        w.Write(dt);
                }

                return text.ToString();
            }
            else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder text = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                    using (var w = new ChoFixedLengthWriter(text, configuration))
                        w.Write(dt);
                }

                return text.ToString();
            }

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoFixedLengthWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                parser.Write(records);

                writer.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:47,代码来源:ChoFixedLengthWriter.cs

在ToTextAll()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamWriter.ToString的代码示例8 - ToTextAll()

    using System.IO;


        public static string ToTextAll(IEnumerable records, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null)
        {
            if (records == null) return null;

            if (typeof(DataTable).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoJSONWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }
            else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoJSONWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }


            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoJSONWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                parser.Configuration.JSONPath = jsonPath;

                parser.Write(records);
                parser.Close();
                writer.Flush();
                
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:53,代码来源:ChoJSONWriter.cs

在ToTextAll()方法中,StreamWriter的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

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