C# StreamWriter.WriteLine的代码示例
通过代码示例来学习C# StreamWriter.WriteLine方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
StreamWriter.WriteLine是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamWriter.WriteLine() 已经帮大家高亮显示了,大家可以重点学习StreamWriter.WriteLine() 方法的写法,从而快速掌握该方法的应用。
StreamWriter.WriteLine的代码示例1 - CanDeleteHydratedFilesWhileTheyAreOpenForWrite()
using System.IO; [TestCase] public void CanDeleteHydratedFilesWhileTheyAreOpenForWrite() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string fileName = "GVFS.sln"; string virtualPath = this.Enlistment.GetVirtualPathTo(fileName); virtualPath.ShouldBeAFile(fileSystem); using (Stream stream = new FileStream(virtualPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) using (StreamReader reader = new StreamReader(stream)) { // First line is empty, so read two lines string line = reader.ReadLine() + reader.ReadLine(); line.Length.ShouldNotEqual(0); File.Delete(virtualPath); this.VerifyExistenceAfterDeleteWhileOpen(virtualPath, fileSystem); using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("newline!"); writer.Flush(); this.VerifyExistenceAfterDeleteWhileOpen(virtualPath, fileSystem); } } virtualPath.ShouldNotExistOnDisk(fileSystem); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:31,代码来源:BasicFileSystemTests.cs
在CanDeleteHydratedFilesWhileTheyAreOpenForWrite()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例2 - OpenFileThenCheckout()
using System.IO; [TestCase] public void OpenFileThenCheckout() { string virtualFile = Path.Combine(this.Enlistment.RepoRoot, GitCommandsTests.EditFilePath); string controlFile = Path.Combine(this.ControlGitRepo.RootPath, GitCommandsTests.EditFilePath); // Open files with ReadWrite sharing because depending on the state of the index (and the mtimes), git might need to read the file // as part of status (while we have the handle open). using (FileStream virtualFS = File.Open(virtualFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) using (StreamWriter virtualWriter = new StreamWriter(virtualFS)) using (FileStream controlFS = File.Open(controlFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) using (StreamWriter controlWriter = new StreamWriter(controlFS)) { this.ValidateGitCommand("checkout -b tests/functional/OpenFileThenCheckout"); virtualWriter.WriteLine("// Adding a line for testing purposes"); controlWriter.WriteLine("// Adding a line for testing purposes"); this.ValidateGitCommand("status"); } // NOTE: Due to optimizations in checkout -b, the modified files will not be included as part of the // success message. Validate that the succcess messages match, and the call to validate "status" below // will ensure that GVFS is still reporting the edited file as modified. string controlRepoRoot = this.ControlGitRepo.RootPath; string gvfsRepoRoot = this.Enlistment.RepoRoot; string command = "checkout -b tests/functional/OpenFileThenCheckout_2"; ProcessResult expectedResult = GitProcess.InvokeProcess(controlRepoRoot, command); ProcessResult actualResult = GitHelpers.InvokeGitAgainstGVFSRepo(gvfsRepoRoot, command); GitHelpers.ErrorsShouldMatch(command, expectedResult, actualResult); actualResult.Errors.ShouldContain("Switched to a new branch"); this.ValidateGitCommand("status"); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:35,代码来源:GitCommandsTests.cs
在OpenFileThenCheckout()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例3 - 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. ///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; } that can be signaled to exit the lock acquisition program.
开发者ID:microsoft,项目名称:VFSForGit,代码行数:72,代码来源:GitHelpers.cs
在RunCommandWithWaitAndStdIn()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例4 - WriteRegistry()
using System.IO; private void WriteRegistry(Dictionary
registry) { string tempFilePath = Path.Combine(this.registryParentFolderPath, RegistryTempName); using (Stream stream = this.fileSystem.OpenFileStream( tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None, callFlushFileBuffers: true)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine(RegistryVersion); foreach (RepoRegistration repo in registry.Values) { writer.WriteLine(repo.ToJson()); } stream.Flush(); } this.fileSystem.MoveAndOverwriteFile(tempFilePath, Path.Combine(this.registryParentFolderPath, RegistryName)); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:25,代码来源:RepoRegistry.cs
在WriteRegistry()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例5 - BuildWxs()
using System.IO; ///
/// Builds the WiX source file (*.wxs) from the specified /// The project. ///instance. /// 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的代码示例类中的WriteLine的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例6 - writeKey()
using System.IO; private static void writeKey(StreamWriter file, Animation.KeyGroup keys, Animation.KeyNode rt, int size, string type, bool useSegmentCompenseateScale = false) { bool isAngular = type == "rotateX" || type == "rotateY" || type == "rotateZ"; string interp = isAngular ? "angular" : "linear"; file.WriteLine("animData {"); file.WriteLine(" input time;"); file.WriteLine($" output {interp};"); file.WriteLine(" weighted 1;"); file.WriteLine(" preInfinity constant;"); file.WriteLine(" postInfinity constant;"); file.WriteLine(" keys {"); if (((Animation.KeyFrame)keys.Keys[0]).InterType == InterpolationType.CONSTANT) size = 1; int f = 1; foreach (Animation.KeyFrame key in keys.Keys) { float v = 0; switch (type) { case "translateX": case "translateY": case "translateZ": v = key.Value; break; case "rotateX": if (rt.RotType == Animation.RotationType.EULER) v = key.Value * Rad2Deg; if (rt.RotType == Animation.RotationType.QUATERNION) { Quaternion q = new Quaternion(rt.XROT.GetValue(key.Frame), rt.YROT.GetValue(key.Frame), rt.ZROT.GetValue(key.Frame), rt.WROT.GetValue(key.Frame)); v = quattoeul(q).X * Rad2Deg; } break; case "rotateY": if (rt.RotType == Animation.RotationType.EULER) v = key.Value * Rad2Deg; if (rt.RotType == Animation.RotationType.QUATERNION) { Quaternion q = new Quaternion(rt.XROT.GetValue(key.Frame), rt.YROT.GetValue(key.Frame), rt.ZROT.GetValue(key.Frame), rt.WROT.GetValue(key.Frame)); v = quattoeul(q).Y * Rad2Deg; } break; case "rotateZ": if (rt.RotType == Animation.RotationType.EULER) v = key.Value * Rad2Deg; if (rt.RotType == Animation.RotationType.QUATERNION) { Quaternion q = new Quaternion(rt.XROT.GetValue(key.Frame), rt.YROT.GetValue(key.Frame), rt.ZROT.GetValue(key.Frame), rt.WROT.GetValue(key.Frame)); v = quattoeul(q).Z * Rad2Deg; } break; case "scaleX": case "scaleY": case "scaleZ": if (useSegmentCompenseateScale) v = 1f / key.Value; else v = key.Value; break; } file.WriteLine(" " + (key.Frame + 1) + " {0:N6} fixed fixed 1 1 0 0 1 0 1;".Replace(",","."), v); } file.WriteLine(" }"); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:73,代码来源:ANIM.cs
在writeKey()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了9次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例7 - WriteExtraSkinningInfo()
using System.IO; //Extra skin data based on https://github.com/Sage-of-Mirrors/SuperBMD/blob/ce1061e9b5f57de112f1d12f6459b938594664a0/SuperBMDLib/source/Model.cs#L193 //Todo this doesn't quite work yet //Need to adjust all mesh name IDs so they are correct private void WriteExtraSkinningInfo(string FileName, Scene outScene, List
Meshes) { StreamWriter test = new StreamWriter(FileName + ".tmp"); StreamReader dae = File.OpenText(FileName); int geomIndex = 0; while (!dae.EndOfStream) { string line = dae.ReadLine(); /* if (line == " ") { AddControllerLibrary(outScene, test); test.WriteLine(line); test.Flush(); } else if (line.Contains(" .WriteLine(line); // test.Flush(); string[] testLn = line.Split('\"'); string name = testLn[3]; string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">"); test.WriteLine(jointLine); test.Flush(); } else if (line.Contains("")) { foreach (Mesh mesh in outScene.Meshes) { test.WriteLine($" "); test.WriteLine($" "); test.Flush(); } test.WriteLine(line); test.Flush(); }*/ if (line.Contains(""); test.WriteLine(" "); test.WriteLine("#skeleton_root "); test.WriteLine(""); test.WriteLine(" "); test.WriteLine(""); test.WriteLine($" "); test.WriteLine(""); test.WriteLine(" .WriteLine($" "); test.Flush(); geomIndex++; } else { test.WriteLine(line); test.Flush(); } /* else if (line.Contains(" ", " "); test.WriteLine(matLine); test.Flush(); }*/ } test.Close(); dae.Close(); File.Copy(FileName + ".tmp", FileName, true); File.Delete(FileName + ".tmp"); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:84,代码来源:AssimpSaver.cs
在WriteExtraSkinningInfo()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了17次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.WriteLine的代码示例8 - Save()
using System.IO; public void Save(System.IO.Stream stream) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(stream)) { foreach (STGenericObject obj in objects) { file.WriteLine($"Obj Name:" + obj.ObjectName); file.WriteLine($"Bone_Suport"); file.WriteLine($"UV_Num:1"); file.WriteLine($"vert_Array"); foreach (Vertex v in obj.vertices) { file.WriteLine($"{v.pos.X},{v.pos.Y},{v.pos.Z}"); file.WriteLine($"{v.nrm.X},{v.nrm.Y},{v.nrm.Z}"); file.WriteLine($"{v.col.X * 255},{v.col.Y * 255},{v.col.Z * 255},{v.col.W * 255}"); file.WriteLine($"{v.uv0.X},{v.uv0.Y}"); // file.WriteLine($"{v.uv1.X},{v.uv1.Y}"); } file.WriteLine($"face_Array"); for (int f = 0; f < obj.faces.Count / 3; f++) { file.WriteLine($"{obj.faces[f] + 1},{obj.faces[f++] + 1},{obj.faces[f++] + 1}"); } file.WriteLine($"bone_Array"); foreach (Vertex v in obj.vertices) { if (v.boneNames.Count == 1) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]}"); if (v.boneNames.Count == 2) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]}"); if (v.boneNames.Count == 3) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]}"); if (v.boneNames.Count == 4) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]} {v.boneNames[3]} {v.boneWeights[3]}"); } } file.Close(); } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:41,代码来源:CsvModels.cs
在Save()方法中,StreamWriter的代码示例类中的WriteLine的代码示例方法一共出现了16次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的StreamWriter.WriteLine方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。