C# Path.ChangeExtension的代码示例
通过代码示例来学习C# Path.ChangeExtension方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
Path.ChangeExtension是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.ChangeExtension() 已经帮大家高亮显示了,大家可以重点学习Path.ChangeExtension() 方法的写法,从而快速掌握该方法的应用。
Path.ChangeExtension的代码示例1 - DeleteStaleTempPrefetchPackAndIdxs()
using System.IO; public virtual void DeleteStaleTempPrefetchPackAndIdxs() { string[] staleTempPacks = this.ReadPackFileNames(Path.Combine(this.Enlistment.GitPackRoot, GitObjects.TempPackFolder), GVFSConstants.PrefetchPackPrefix); foreach (string stalePackPath in staleTempPacks) { string staleIdxPath = Path.ChangeExtension(stalePackPath, ".idx"); string staleTempIdxPath = Path.ChangeExtension(stalePackPath, TempIdxExtension); EventMetadata metadata = CreateEventMetadata(); metadata.Add("stalePackPath", stalePackPath); metadata.Add("staleIdxPath", staleIdxPath); metadata.Add("staleTempIdxPath", staleTempIdxPath); metadata.Add(TracingConstants.MessageKey.InfoMessage, "Deleting stale temp pack and/or idx file"); this.fileSystem.TryDeleteFile(staleTempIdxPath, metadataKey: nameof(staleTempIdxPath), metadata: metadata); this.fileSystem.TryDeleteFile(staleIdxPath, metadataKey: nameof(staleIdxPath), metadata: metadata); this.fileSystem.TryDeleteFile(stalePackPath, metadataKey: nameof(stalePackPath), metadata: metadata); this.Tracer.RelatedEvent(EventLevel.Informational, nameof(this.DeleteStaleTempPrefetchPackAndIdxs), metadata); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:23,代码来源:GitObjects.cs
在DeleteStaleTempPrefetchPackAndIdxs()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例2 - CleanStaleIdxFiles()
using System.IO; // public only for unit tests public List
CleanStaleIdxFiles(out int numDeletionBlocked) { List packDirContents = this.Context .FileSystem .ItemsInDirectory(this.Context.Enlistment.GitPackRoot) .ToList(); numDeletionBlocked = 0; List deletedIdxFiles = new List (); // If something (probably VFS for Git) has a handle open to a ".idx" file, then // the 'git multi-pack-index expire' command cannot delete it. We should come in // later and try to clean these up. Count those that we are able to delete and // those we still can't. foreach (DirectoryItemInfo info in packDirContents) { if (string.Equals(Path.GetExtension(info.Name), ".idx", GVFSPlatform.Instance.Constants.PathComparison)) { string pairedPack = Path.ChangeExtension(info.FullName, ".pack"); if (!this.Context.FileSystem.FileExists(pairedPack)) { if (this.Context.FileSystem.TryDeleteFile(info.FullName)) { deletedIdxFiles.Add(info.Name); } else { numDeletionBlocked++; } } } } return deletedIdxFiles; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:40,代码来源:PackfileMaintenanceStep.cs
在CleanStaleIdxFiles()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例3 - UpdateKeepPacks()
using System.IO; ///
/// Ensure the prefetch pack with most-recent timestamp has an associated /// ".keep" file. This prevents any Git command from deleting the pack. /// /// Delete the previous ".keep" file(s) so that pack can be deleted when they /// are not the most-recent pack. /// private void UpdateKeepPacks() { if (!this.TryGetMaxGoodPrefetchTimestamp(out long maxGoodTimeStamp, out string error)) { return; } string prefix = $"prefetch-{maxGoodTimeStamp}-"; DirectoryItemInfo info = this.Context .FileSystem .ItemsInDirectory(this.Context.Enlistment.GitPackRoot) .Where(item => item.Name.StartsWith(prefix) && string.Equals(Path.GetExtension(item.Name), ".pack", GVFSPlatform.Instance.Constants.PathComparison)) .FirstOrDefault(); if (info == null) { this.Context.Tracer.RelatedWarning(this.CreateEventMetadata(), $"Could not find latest prefetch pack, starting with {prefix}"); return; } string newKeepFile = Path.ChangeExtension(info.FullName, ".keep"); if (!this.Context.FileSystem.TryWriteAllText(newKeepFile, string.Empty)) { this.Context.Tracer.RelatedWarning(this.CreateEventMetadata(), $"Failed to create .keep file at {newKeepFile}"); return; } foreach (string keepFile in this.Context .FileSystem .ItemsInDirectory(this.Context.Enlistment.GitPackRoot) .Where(item => item.Name.EndsWith(".keep")) .Select(item => item.FullName)) { if (!keepFile.Equals(newKeepFile)) { this.Context.FileSystem.TryDeleteFile(keepFile); } } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:50,代码来源:PrefetchStep.cs
在UpdateKeepPacks()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例4 - PrefetchBuildsIdxWhenMissingFromPrefetchPack()
using System.IO; [TestCase, Order(2)] public void PrefetchBuildsIdxWhenMissingFromPrefetchPack() { string[] prefetchPacks = this.ReadPrefetchPackFileNames(); prefetchPacks.Length.ShouldBeAtLeast(1, "There should be at least one prefetch pack"); string idxPath = Path.ChangeExtension(prefetchPacks[0], ".idx"); idxPath.ShouldBeAFile(this.fileSystem); File.SetAttributes(idxPath, FileAttributes.Normal); this.fileSystem.DeleteFile(idxPath); idxPath.ShouldNotExistOnDisk(this.fileSystem); // Prefetch should rebuild the missing idx this.Enlistment.Prefetch("--commits"); this.PostFetchJobShouldComplete(); idxPath.ShouldBeAFile(this.fileSystem); // All of the original prefetch packs should still be present string[] newPrefetchPacks = this.ReadPrefetchPackFileNames(); newPrefetchPacks.ShouldContain(prefetchPacks, (item, expectedValue) => { return string.Equals(item, expectedValue); }); this.AllPrefetchPacksShouldHaveIdx(newPrefetchPacks); this.TempPackRoot.ShouldBeADirectory(this.fileSystem).WithNoItems(); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:26,代码来源:PrefetchVerbWithoutSharedCacheTests.cs
在PrefetchBuildsIdxWhenMissingFromPrefetchPack()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例5 - DigitalySign()
using System.IO; //static Task
ExecuteInNewContext (Func action) //{ // var taskResult = new TaskCompletionSource (); // var asyncFlow = ExecutionContext.SuppressFlow(); // try // { // Task.Run(() => // { // try // { // var result = action(); // taskResult.SetResult(result); // } // catch (Exception exception) // { // taskResult.SetException(exception); // } // }) // .Wait(); // } // finally // { // asyncFlow.Undo(); // } // return taskResult.Task; //} //static public string EmmitComWxs(string fileIn, string fileOut = null, string extraArgs = null) //{ // if (fileOut == null) // fileOut = IO.Path.ChangeExtension(fileIn, "wxs"); // //heat.exe fileIn -gg -out fileOut // string args = $"\"{fileIn}\" -gg -out \"{fileOut}\" {extraArgs}"; // var tool = new ExternalTool // { // WellKnownLocations = Compiler.WixLocation, // ExePath = "heat.exe", // Arguments = args // }; // if (tool.ConsoleRun() == 0) // return fileOut; // else // return null; //} /// /// Applies digital signature to a file (e.g. msi, exe, dll) with MS /// The file to sign. /// Specify the signing certificate in a file. If this file is a PFX with a password, the password may be supplied /// with theSignTool.exe utility. ///If you need to specify extra SignTool.exe parameters or the location of the tool use the overloaded ///DigitalySign signaturepassword parameter. /// The timestamp server's URL. If this option is not present, the signed file will not be timestamped. /// A warning is generated if timestamping fails. /// The password to use when opening the PFX file. ///Exit code of the /// ///SignTool.exe process.The following is an example of signing static public int DigitalySign(string fileToSign, string pfxFile, string timeURL, string password) { return DigitalySign(fileToSign, pfxFile, timeURL, password, null); }Setup.msi file. ////// WixSharp.CommonTasks.Tasks.DigitalySign( /// "Setup.msi", /// "MyCert.pfx", /// "http://timestamp.verisign.com/scripts/timstamp.dll", /// "MyPassword"); ///
///
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:78,代码来源:CommonTasks.cs
在DigitalySign()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例6 - BuildCmd()
using System.IO; ///
/// Builds the WiX source file and generates batch file capable of building /// WiX/MSI bootstrapper with WiX toolset. /// /// The project. /// The path to the batch file to be created. ///Wix compiler/linker cannot be found public static string BuildCmd(Bundle project, string path = null) { if (path == null) path = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, "Build_" + project.OutFileName) + ".cmd"); path = path.ExpandEnvVars(); //System.Diagnostics.Debug.Assert(false); string wixLocationEnvVar = $"set WixLocation={WixLocation}" + Environment.NewLine; string compiler = Utils.PathCombine(WixLocation, "candle.exe"); string linker = Utils.PathCombine(WixLocation, "light.exe"); string batchFile = path; if (!IO.File.Exists(compiler) || !IO.File.Exists(linker)) { Compiler.OutputWriteLine("Wix binaries cannot be found. Expected location is " + IO.Path.GetDirectoryName(compiler)); throw new ApplicationException("Wix compiler/linker cannot be found"); } else { string wxsFile = BuildWxs(project); if (!project.SourceBaseDir.IsEmpty()) Environment.CurrentDirectory = project.SourceBaseDir; string objFile = IO.Path.ChangeExtension(wxsFile, ".wixobj"); string pdbFile = IO.Path.ChangeExtension(wxsFile, ".wixpdb"); string extensionDlls = ""; // note we need to avoid possible duplications cause by non expanded envars // %wix_location%\ext.dll vs c:\Program Files\...\ext.dll foreach (string dll in project.WixExtensions.DistinctBy(x => x.ExpandEnvVars())) extensionDlls += " -ext \"" + dll + "\""; string wxsFiles = ""; foreach (string file in project.WxsFiles.Distinct()) wxsFiles += " \"" + file + "\""; var candleOptions = CandleOptions + " " + project.CandleOptions; string batchFileContent = wixLocationEnvVar + "\"" + compiler + "\" " + candleOptions + " " + extensionDlls + " \"" + wxsFile + "\" "; string outDir = null; if (wxsFiles.IsNotEmpty()) { batchFileContent += wxsFiles; outDir = IO.Path.GetDirectoryName(wxsFile); // if multiple files are specified candle expect a path for the -out switch // or no path at all (use current directory) // note the '\' character must be escaped twice: as a C# string and as a CMD char if (outDir.IsNotEmpty()) batchFileContent += $" -out \"{outDir}\\\\\""; } else batchFileContent += $" -out \"{objFile}\""; batchFileContent += "\r\n"; string fragmentObjectFiles = project.WxsFiles .Distinct() .JoinBy(" ", file => "\"" + outDir.PathCombine(IO.Path.GetFileNameWithoutExtension(file)) + ".wixobj\""); string lightOptions = LightOptions + " " + project.LightOptions; if (fragmentObjectFiles.IsNotEmpty()) lightOptions += " " + fragmentObjectFiles; if (path.IsNotEmpty()) lightOptions += " -out \"" + IO.Path.ChangeExtension(objFile, ".exe") + "\""; batchFileContent += "\"" + linker + "\" " + lightOptions + " \"" + objFile + "\" " + extensionDlls + " -cultures:" + project.Language + "\r\npause"; batchFileContent = batchFileContent.ExpandEnvVars(); using (var sw = new IO.StreamWriter(batchFile)) sw.Write(batchFileContent); } return path; }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:90,代码来源:Compiler.Bootstrapper.cs
在BuildCmd()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例7 - EditInExternalProgram()
using System.IO; private void EditInExternalProgram(bool UseDefaultEditor = true) { if (!ActiveTexture.CanEdit || !IsFinished) return; ImageProgramSettings settings = new ImageProgramSettings(); settings.LoadImage(ActiveTexture); if (settings.ShowDialog() == DialogResult.OK) { UseDefaultEditor = !settings.OpenDefaultProgramSelection; string UseExtension = settings.GetSelectedExtension(); FormatToChange = settings.GetSelectedImageFormat(); string TemporaryName = Path.GetTempFileName(); Utils.DeleteIfExists(Path.ChangeExtension(TemporaryName, UseExtension)); File.Move(TemporaryName, Path.ChangeExtension(TemporaryName, UseExtension)); TemporaryName = Path.ChangeExtension(TemporaryName, UseExtension); switch (UseExtension) { case ".dds": ActiveTexture.SaveDDS(TemporaryName, true, false, CurArrayDisplayLevel, CurMipDisplayLevel); break; case ".astc": ActiveTexture.SaveASTC(TemporaryName, true, false, CurArrayDisplayLevel, CurMipDisplayLevel); break; case ".tga": ActiveTexture.SaveTGA(TemporaryName, true, false, CurArrayDisplayLevel, CurMipDisplayLevel); break; default: ActiveTexture.SaveBitMap(TemporaryName, true, false, CurArrayDisplayLevel, CurMipDisplayLevel); break; } //Start watching for changes FileWatcher.EnableRaisingEvents = true; FileWatcher.Filter = Path.GetFileName(TemporaryName); if (UseDefaultEditor) Process.Start(TemporaryName); else ShowOpenWithDialog(TemporaryName); } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:46,代码来源:ImageEditorBase.cs
在EditInExternalProgram()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.ChangeExtension的代码示例8 - CreateProjectItemFromFile()
using System.IO; protected RazorProjectItem CreateProjectItemFromFile(string filePath = null) { if (FileName == null) { var message = $"{nameof(CreateProjectItemFromFile)} should only be called from an integration test, ({nameof(FileName)} is null)."; throw new InvalidOperationException(message); } var suffixIndex = FileName.LastIndexOf("_"); var normalizedFileName = suffixIndex == -1 ? FileName : FileName.Substring(0, suffixIndex); var sourceFileName = Path.ChangeExtension(normalizedFileName, FileExtension); var testFile = TestFile.Create(sourceFileName, GetType().GetTypeInfo().Assembly); if (!testFile.Exists()) { throw new XunitException($"The resource {sourceFileName} was not found."); } var fileContent = testFile.ReadAllText(); var normalizedContent = NormalizeNewLines(fileContent); var workingDirectory = Path.GetDirectoryName(FileName); var fullPath = sourceFileName; // Normalize to forward-slash - these strings end up in the baselines. fullPath = fullPath.Replace('\\', '/'); sourceFileName = sourceFileName.Replace('\\', '/'); // FilePaths in Razor are **always** are of the form '/a/b/c.cshtml' filePath = filePath ?? sourceFileName; if (!filePath.StartsWith("/")) { filePath = '/' + filePath; } var projectItem = new TestRazorProjectItem( basePath: workingDirectory, filePath: filePath, physicalPath: fullPath, relativePhysicalPath: sourceFileName) { Content = fileContent, }; return projectItem; }
开发者ID:aspnet,项目名称:Razor,代码行数:46,代码来源:IntegrationTestBase.cs
在CreateProjectItemFromFile()方法中,Path的代码示例类中的ChangeExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的Path.ChangeExtension方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。