C# File.ReadAllText的代码示例
通过代码示例来学习C# File.ReadAllText方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
File.ReadAllText是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.ReadAllText() 已经帮大家高亮显示了,大家可以重点学习File.ReadAllText() 方法的写法,从而快速掌握该方法的应用。
File.ReadAllText的代码示例1 - Execute()
using System.IO; public override bool Execute() { string templateFilePath = this.Template.ItemSpec; IDictionary
properties = ParseProperties(this.Template.GetMetadata("Properties")); string outputFileDirectory = Path.GetDirectoryName(this.OutputFile); if (!File.Exists(templateFilePath)) { this.Log.LogError("Failed to find template file '{0}'.", templateFilePath); return false; } // Copy the template to the destination to keep the same file mode bits/ACLs as the template File.Copy(templateFilePath, this.OutputFile, true); this.Log.LogMessage(MessageImportance.Low, "Reading template contents"); string template = File.ReadAllText(this.OutputFile); this.Log.LogMessage(MessageImportance.Normal, "Compiling template '{0}'", templateFilePath); string compiled = Compile(template, properties); if (!Directory.Exists(outputFileDirectory)) { this.Log.LogMessage(MessageImportance.Low, "Creating output directory '{0}'", outputFileDirectory); Directory.CreateDirectory(outputFileDirectory); } this.Log.LogMessage(MessageImportance.Normal, "Writing compiled template to '{0}'", this.OutputFile); File.WriteAllText(this.OutputFile, compiled); this.CompiledTemplate = new TaskItem(this.OutputFile, this.Template.CloneCustomMetadata()); return true; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:37,代码来源:CompileTemplatedFile.cs
在Execute()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例2 - GetObjectRoot()
using System.IO; public string GetObjectRoot(FileSystemRunner fileSystem) { string mappingFile = Path.Combine(this.LocalCacheRoot, "mapping.dat"); mappingFile.ShouldBeAFile(fileSystem); HashSet
allowedFileNames = new HashSet (FileSystemHelpers.PathComparer) { "mapping.dat", "mapping.dat.lock" // mapping.dat.lock can be present, but doesn't have to be present }; this.LocalCacheRoot.ShouldBeADirectory(fileSystem).WithFiles().ShouldNotContain(f => !allowedFileNames.Contains(f.Name)); string mappingFileContents = File.ReadAllText(mappingFile); mappingFileContents.ShouldNotBeNull(); string[] objectRootEntries = mappingFileContents.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) .Where(x => x.IndexOf(this.RepoUrl, StringComparison.OrdinalIgnoreCase) >= 0) .ToArray(); objectRootEntries.Length.ShouldEqual(1, $"Should be only one entry for repo url: {this.RepoUrl} mapping file content: {mappingFileContents}"); objectRootEntries[0].Substring(0, 2).ShouldEqual("A ", $"Invalid mapping entry for repo: {objectRootEntries[0]}"); JObject rootEntryJson = JObject.Parse(objectRootEntries[0].Substring(2)); string objectRootFolder = rootEntryJson.GetValue("Value").ToString(); objectRootFolder.ShouldNotBeNull(); objectRootFolder.Length.ShouldBeAtLeast(1, $"Invalid object root folder: {objectRootFolder} for {this.RepoUrl} mapping file content: {mappingFileContents}"); return Path.Combine(this.LocalCacheRoot, objectRootFolder, "gitObjects"); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:29,代码来源:GVFSFunctionalTestEnlistment.cs
在GetObjectRoot()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例3 - TryParseHead()
using System.IO; private static bool TryParseHead(Enlistment enlistment, List
messages) { string refPath = Path.Combine(enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Head); if (!File.Exists(refPath)) { messages.Add("Could not find ref file for '" + GVFSConstants.DotGit.Head + "'"); return false; } string refContents; try { refContents = File.ReadAllText(refPath).Trim(); } catch (IOException ex) { messages.Add($"IOException while reading {GVFSConstants.DotGit.Head}: " + ex.Message); return false; } const string MinimallyValidRef = "ref: refs/"; if (refContents.StartsWith(MinimallyValidRef, StringComparison.OrdinalIgnoreCase) || SHA1Util.IsValidShaFormat(refContents)) { return true; } messages.Add("Invalid contents found in '" + GVFSConstants.DotGit.Head + "': " + refContents); return false; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:32,代码来源:GitHeadRepairJob.cs
在TryParseHead()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例4 - IsFastFetchVersionMarkerCurrent()
using System.IO; private bool IsFastFetchVersionMarkerCurrent() { if (File.Exists(this.versionMarkerFile)) { int version; string marker = File.ReadAllText(this.versionMarkerFile, Encoding.ASCII); bool isMarkerCurrent = int.TryParse(marker, out version) && (version == CurrentFastFetchIndexVersion); this.tracer.RelatedEvent(EventLevel.Informational, "PreviousMarker", new EventMetadata() { { "Content", marker }, { "IsCurrent", isMarkerCurrent } }, Keywords.Telemetry); return isMarkerCurrent; } this.tracer.RelatedEvent(EventLevel.Informational, "NoPreviousMarkerFound", null, Keywords.Telemetry); return false; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:16,代码来源:Index.cs
在IsFastFetchVersionMarkerCurrent()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例5 - SecondCloneDoesNotDownloadAdditionalObjects()
using System.IO; [TestCase] public void SecondCloneDoesNotDownloadAdditionalObjects() { GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment(); File.ReadAllText(Path.Combine(enlistment1.RepoRoot, WellKnownFile)); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); string[] allObjects = Directory.EnumerateFiles(enlistment1.LocalCacheRoot, "*", SearchOption.AllDirectories).ToArray(); GVFSFunctionalTestEnlistment enlistment2 = this.CloneAndMountEnlistment(); File.ReadAllText(Path.Combine(enlistment2.RepoRoot, WellKnownFile)); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment2); enlistment2.LocalCacheRoot.ShouldEqual(enlistment1.LocalCacheRoot, "Sanity: Local cache roots are expected to match."); Directory.EnumerateFiles(enlistment2.LocalCacheRoot, "*", SearchOption.AllDirectories) .ShouldMatchInOrder(allObjects); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:21,代码来源:SharedCacheTests.cs
在SecondCloneDoesNotDownloadAdditionalObjects()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例6 - Fix_Issue_1132()
[Fact] [Description("Issue #1132")] public void Fix_Issue_1132() { var i = 0; var project = new Project("CableScheduler", new Dir(@"%ProgramFiles%\CADbloke\CableScheduler", new Files($"{Environment.CurrentDirectory}\\*.*", f => i++ < 1)), new Dir(@"%ProgramMenu%\CADbloke\CableScheduler", new ExeFileShortcut("Cable Scheduler", $"[INSTALLDIR]Test.exe", ""))); project.ResolveWildCards(pruneEmptyDirectories: true); var wsx = project.BuildWxs(); var xml = System.IO.File.ReadAllText(wsx); Assert.True(xml.Contains("
static public RegValue[] ImportFrom(string regFile) { var result = new List (); string content = System.IO.File.ReadAllText(regFile); content = Regex.Replace(content, @"\r\n|\n\r|\n|\r", "\r\n"); var parser = new RegParser(); char[] delimiter = { '\\' }; foreach (KeyValuePair > entry in parser.Parse(content)) foreach (KeyValuePair item in entry.Value) { string path = entry.Key; var regval = new RegValue(); regval.Root = GetHive(path); regval.Key = path.Split(delimiter, 2).Last(); regval.Name = item.Key; regval.Value = Deserialize(item.Value, parser.Encoding); if (regval.Value != null) result.Add(regval); } return result.ToArray(); }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:30,代码来源:RegFileImporter.cs
在ImportFrom()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllText的代码示例8 - ReplaceAction()
using System.IO; private void ReplaceAction(object sender, EventArgs args) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Supported Formats|*.dae;*.fbx;*.json;|" + "FBX |*.fbx|" + "DAE |*.dae|" + "JSON |*.json|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { string ext = Utils.GetExtension(ofd.FileName); if (ext == ".json") { var model = JsonConvert.DeserializeObject
( System.IO.File.ReadAllText(ofd.FileName)); ReloadModel(model); Model.UpdateVertexData(true); } else { AssimpData assimp = new AssimpData(); bool IsLoaded = assimp.LoadFile(ofd.FileName); if (!IsLoaded) return; GFLXModelImporter dialog = new GFLXModelImporter(); dialog.LoadMeshes(assimp.objects, assimp.materials, Model.GenericMaterials, Model.GenericMeshes); if (dialog.ShowDialog() == DialogResult.OK) { ImportModel(dialog, assimp.materials, assimp.objects, assimp.skeleton); } } } LoadEditor (); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:40,代码来源:GFBMDL.cs
在ReplaceAction()方法中,File的代码示例类中的ReadAllText的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的File.ReadAllText方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。