C# FileInfo.Replace的代码示例

通过代码示例来学习C# FileInfo.Replace方法

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


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

FileInfo.Replace的代码示例1 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if ( Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }
                        files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

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

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

FileInfo.Replace的代码示例2 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if (Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }

                        if (fileInfo.FileData.Length > 0)
                            files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

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

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

FileInfo.Replace的代码示例3 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if (Chunks[i].ChunkData is SWUTexture)
                            {
                                SWUTexture texFile = (SWUTexture)Chunks[i].ChunkData;
                                if (Chunks[i].FileSize != 0)
                                    texFile.ImageData = reader.ReadBytes((int)Chunks[i].FileSize);

                                continue;
                            }
                            if ( Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }

                        files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

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

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

FileInfo.Replace的代码示例4 - GetItem()

    using System.IO;

        public override RazorProjectItem GetItem(string path)
        {
            var absoluteBasePath = NormalizeAndEnsureValidPath("/");
            var absolutePath = NormalizeAndEnsureValidPath(path);

            var file = new FileInfo(absolutePath);
            if (!absolutePath.StartsWith(absoluteBasePath))
            {
                throw new InvalidOperationException($"The file '{file.FullName}' is not a descendent of the base path '{absoluteBasePath}'.");
            }

            var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
            var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/');

            return new DefaultRazorProjectItem("/", filePath, relativePhysicalPath, new FileInfo(absolutePath));
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:18,代码来源:DefaultRazorProjectFileSystem.cs

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

FileInfo.Replace的代码示例5 - LoadFile()

    using System.IO;

		/// 
		/// Loads the specified file.
		/// 
		/// 
		public void LoadFile(string filePath)
		{
			var path = System.Text.RegularExpressions.Regex.Replace(filePath.Trim(), "^\"(.+)\"$", "$1");
			FileInfo file = null;
			try
			{
				file = new FileInfo(path);
			}
			catch (ArgumentNullException)
			{
				this.Error("The file path is empty");
			}
			catch (ArgumentException)
			{
				this.Error("The file path is badly formed.");
			}
			catch (PathTooLongException)
			{
				this.Error("The file path is too long.");
			}
			catch (NotSupportedException)
			{
				this.Error("The file path contains invalid characters.");
			}
			if (file == null) return;
			if (!file.Exists)
			{
				this.Error(string.Format("File '{0}' does not exist.", file.FullName));
				if (SelectedMsiFile != null)
					ViewLeakedAbstraction.SelectedMsiFileFullName = SelectedMsiFile.FullName;
				return;
			}
			SelectedMsiFile = file;
			this.LoadCurrentFile();
		}
    

开发者ID:activescott,项目名称:lessmsi,代码行数:41,代码来源:MainFormPresenter.cs

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

FileInfo.Replace的代码示例6 - ReplaceParams()

    using System.IO;

        #endregion

        #region Public methods

        public string ReplaceParams(ILogLine logLine, int lineNum, string fileName)
        {
            FileInfo fileInfo = new FileInfo(fileName);
            StringBuilder builder = new StringBuilder(this.argLine);
            builder.Replace("%L", "" + lineNum);
            builder.Replace("%P",
                fileInfo.DirectoryName.Contains(" ") ? "\"" + fileInfo.DirectoryName + "\"" : fileInfo.DirectoryName);
            builder.Replace("%N", fileInfo.Name.Contains(" ") ? "\"" + fileInfo.Name + "\"" : fileInfo.Name);
            builder.Replace("%F",
                fileInfo.FullName.Contains(" ") ? "\"" + fileInfo.FullName + "\"" : fileInfo.FullName);
            builder.Replace("%E",
                fileInfo.Extension.Contains(" ") ? "\"" + fileInfo.Extension + "\"" : fileInfo.Extension);
            string stripped = StripExtension(fileInfo.Name);
            builder.Replace("%M", stripped.Contains(" ") ? "\"" + stripped + "\"" : stripped);
            int sPos = 0;
            string reg;
            string replace;
            do
            {
                reg = GetNextGroup(builder, ref sPos);
                replace = GetNextGroup(builder, ref sPos);
                if (reg != null && replace != null)
                {
                    string result = Regex.Replace(logLine.FullLine, reg, replace);
                    builder.Insert(sPos, result);
                }
            } while (replace != null);
            return builder.ToString();
        }
    

开发者ID:zarunbal,项目名称:LogExpert,代码行数:35,代码来源:ParamParser.cs

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

FileInfo.Replace的代码示例7 - ParseParameter()

    using System.IO;
        public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context)
        {
            string includeFilename = Environment.ExpandEnvironmentVariables(parameters[0]);
            IncludeType matchType = IncludeType.Relative;
            if (parameters.Length > 1)
            {
                string incType = parameters[1].Replace("Sharpmake.", "");
                incType = incType.Replace("IncludeType.", "");
                if (!Enum.TryParse(incType, out matchType))
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include invalid include type used ({0})", parameters[1]);
                }
            }
            string includeAbsolutePath = Path.IsPathRooted(includeFilename) ? includeFilename : null;

            if (Util.IsPathWithWildcards(includeFilename))
            {
                if (matchType != IncludeType.Relative)
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include with non-relative match types, wildcards are not supported ({0})", includeFilename);
                }
                includeAbsolutePath = includeAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, includeFilename);
                context.AddSourceFiles(Util.DirectoryGetFilesWithWildcards(includeAbsolutePath));
            }
            else
            {
                includeAbsolutePath = includeAbsolutePath ?? Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename);

                if (matchType == IncludeType.Relative)
                {
                    if (!Util.FileExists(includeAbsolutePath))
                        includeAbsolutePath = Util.GetCapitalizedPath(includeAbsolutePath);
                }
                else
                {
                    string matchIncludeInParentPath = MatchIncludeInParentPath(includeFilename, sourceFilePath.DirectoryName, matchType);
                    if (matchIncludeInParentPath == null)
                        throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found '{0}'[{1}]. Search started from '{2}'", includeFilename, matchType, sourceFilePath.DirectoryName);

                    includeAbsolutePath = Util.GetCapitalizedPath(matchIncludeInParentPath);
                }

                if (!Util.FileExists(includeAbsolutePath))
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found {0}", includeFilename);

                context.AddSourceFile(includeAbsolutePath);
            }
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:49,代码来源:AttributeParsers.cs

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

FileInfo.Replace的代码示例8 - BlobGenerateFile()

    using System.IO;

        private string BlobGenerateFile(string blobPath, IEnumerable sourceFiles, string filename, List configurations, string header, string footer)
        {
            string blobFileName = Path.Combine(blobPath, filename + BlobExtension);

            FileInfo blobFileInfo = new FileInfo(blobFileName);
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.Write("// generated by sharpmake" + Environment.NewLine + Environment.NewLine);

            Configuration configurationPrecomp = null;
            foreach (Configuration conf in configurations)
            {
                if (conf.PrecompHeader != null && conf.PrecompSource != null)
                {
                    if (configurationPrecomp == null)
                        configurationPrecomp = conf;
                    else if (conf.PrecompHeader != configurationPrecomp.PrecompHeader)
                        throw new Error("blob error: {0} project configurations using the same blob must all have the same precomp header : {1} and {2}", ClassName, configurationPrecomp.Target, conf.Target);
                }
            }

            // include precomp if needed
            if (configurationPrecomp != null)
                writer.Write("#include \"{0}\"" + Environment.NewLine + Environment.NewLine, configurationPrecomp.PrecompHeader.Replace(Util.WindowsSeparator, Util.UnixSeparator));

            if (header != null)
                writer.WriteLine(header + Environment.NewLine);

            foreach (string sourceFileFullPath in sourceFiles)
            {
                string sourceFile = BlobFixCasing ? Util.GetCapitalizedPath(sourceFileFullPath) : sourceFileFullPath;
                string sourceFileRelative = Util.PathGetRelative(blobFileInfo.Directory.FullName, sourceFile).Replace(Util.WindowsSeparator, Util.UnixSeparator);

                // Visual Studio will append the relative include path to the blob file path and will not resolve it before it is searching
                // for the included file in the file system. If that search path is longer than 256 characters it will fail to find it.
                // If the relative include file path that Visual Studio will use internally is too long use the absolute file path
                if (blobFileInfo.Directory.FullName.Length + sourceFileRelative.Length > 255)
                    sourceFileRelative = sourceFile.Replace(Util.WindowsSeparator, Util.UnixSeparator);

                // If the file path is too long the include will fail
                if (sourceFileRelative.Length > 256)
                    throw new Error("include path too long error: '{0}'", sourceFileRelative);

                string sourceFileDisplay = Util.PathGetRelative(SourceRootPath, sourceFile).Replace(Util.WindowsSeparator, Util.UnixSeparator);
                if (sourceFileDisplay.StartsWith("./", StringComparison.Ordinal))
                    sourceFileDisplay = sourceFileDisplay.Substring(2, sourceFileDisplay.Length - 2);

                if (BlobPragmaMessageEnabled)
                {
                    writer.Write("#pragma message(\"{0} - {1}\")" + Environment.NewLine, blobFileInfo.Name, sourceFileDisplay);
                }
                writer.Write("#include \"{0}\"" + Environment.NewLine + Environment.NewLine, sourceFileRelative);
            }

            if (footer != null)
                writer.WriteLine(footer + Environment.NewLine);

            // Write the blob file
            writer.Flush();

            bool written = Builder.Instance.Context.WriteGeneratedFile(null, blobFileInfo, stream);
            if (written)
                BlobGenerated++;
            else
                BlobUpdateToDate++;
            writer.Close();

            return blobFileName;
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:72,代码来源:Project.cs

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

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