C# FileStream.Equals的代码示例

通过代码示例来学习C# FileStream.Equals方法

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


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

FileStream.Equals的代码示例1 - PrefetchFailsWhenItCannotRemoveABadPrefetchPack()

    using System.IO;

        [TestCase, Order(5)]
        public void PrefetchFailsWhenItCannotRemoveABadPrefetchPack()
        {
            this.Enlistment.UnmountGVFS();

            string[] prefetchPacks = this.ReadPrefetchPackFileNames();
            long mostRecentPackTimestamp = this.GetMostRecentPackTimestamp(prefetchPacks);

            // Create a bad pack that is newer than the most recent pack
            string badContents = "BADPACK";
            string badPackPath = Path.Combine(this.PackRoot, $"{PrefetchPackPrefix}-{mostRecentPackTimestamp + 1}-{Guid.NewGuid().ToString("N")}.pack");
            this.fileSystem.WriteAllText(badPackPath, badContents);
            badPackPath.ShouldBeAFile(this.fileSystem).WithContents(badContents);

            // Open a handle to the bad pack that will prevent prefetch from being able to delete it
            using (FileStream stream = new FileStream(badPackPath, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                string output = this.Enlistment.Prefetch("--commits", failOnError: false);
                output.ShouldContain($"Unable to delete {badPackPath}");
            }

            // After handle is closed prefetch should succeed
            this.Enlistment.Prefetch("--commits");
            this.PostFetchJobShouldComplete();

            badPackPath.ShouldNotExistOnDisk(this.fileSystem);

            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,代码行数:34,代码来源:PrefetchVerbWithoutSharedCacheTests.cs

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

FileStream.Equals的代码示例2 - Compile()

    using System.IO;

        private Assembly Compile(IBuilderContext builderContext, IEnumerable syntaxTrees, string libraryFile, HashSet fileReferences)
        {
            // Add references
            var metadataReferences = new List();

            foreach (var reference in fileReferences.Where(r => !string.IsNullOrEmpty(r)))
            {
                // Skip references that are already provided by the runtime
                if (BasicReferenceAssemblies.All.Any(a => string.Equals(Path.GetFileName(reference), a.FilePath, StringComparison.OrdinalIgnoreCase)))
                    continue;
                metadataReferences.Add(MetadataReference.CreateFromFile(reference));
            }

            metadataReferences.AddRange(BasicReferenceAssemblies.All);

            // suppress assembly redirect warnings
            // cf. https://github.com/dotnet/roslyn/issues/19640
            var noWarn = new List>
            {
                new KeyValuePair("CS1701", ReportDiagnostic.Suppress),
                new KeyValuePair("CS1702", ReportDiagnostic.Suppress),
            };

            // Compile
            var compilationOptions = new CSharpCompilationOptions(
                OutputKind.DynamicallyLinkedLibrary,
                optimizationLevel: (builderContext == null || builderContext.DebugScripts) ? OptimizationLevel.Debug : OptimizationLevel.Release,
                warningLevel: 4,
                specificDiagnosticOptions: noWarn,
                deterministic: true
            );

            var assemblyName = libraryFile != null ? Path.GetFileNameWithoutExtension(libraryFile) : $"Sharpmake_{new Random().Next():X8}" + GetHashCode();
            var compilation = CSharpCompilation.Create(assemblyName, syntaxTrees, metadataReferences, compilationOptions);
            string pdbFilePath = libraryFile != null ? Path.ChangeExtension(libraryFile, ".pdb") : null;

            using (var dllStream = new MemoryStream())
            using (var pdbStream = new MemoryStream())
            {
                EmitResult result = compilation.Emit(
                    dllStream,
                    pdbStream,
                    options: new EmitOptions(
                        debugInformationFormat: DebugInformationFormat.PortablePdb,
                        pdbFilePath: pdbFilePath
                    )
                );

                bool throwErrorException = builderContext == null || builderContext.CompileErrorBehavior == BuilderCompileErrorBehavior.ThrowException;
                LogCompilationResult(result, throwErrorException);

                if (result.Success)
                {
                    if (libraryFile != null)
                    {
                        dllStream.Seek(0, SeekOrigin.Begin);
                        using (var fileStream = new FileStream(libraryFile, FileMode.Create))
                            dllStream.CopyTo(fileStream);

                        pdbStream.Seek(0, SeekOrigin.Begin);
                        using (var pdbFileStream = new FileStream(pdbFilePath, FileMode.Create))
                            pdbStream.CopyTo(pdbFileStream);

                        return Assembly.LoadFrom(libraryFile);
                    }

                    return Assembly.Load(dllStream.GetBuffer(), pdbStream.GetBuffer());
                }
            }

            return null;
        }
    

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

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

FileStream.Equals的代码示例3 - GetFile()

    using System.IO;

        /**
         *
         * @param sampleFileName    the name of the test file
         * @return
         * @throws RuntimeException if the file was not found
         */
        public FileStream GetFile(String sampleFileName)
        {
            string path=_resolvedDataDir+sampleFileName;
            if (!File.Exists(path))
            {
                throw new Exception("Sample file '" + sampleFileName
                        + "' not found in data dir '" + _resolvedDataDir + "'");
            }
            //try
            //{
            //    if (sampleFileName.Length > 0 && !sampleFileName.Equals(f.getCanonicalFile().getName()))
            //    {
            //        throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName
            //                + "' but actual file is '" + f.getCanonicalFile().getName() + "'");
            //    }
            //}
            //catch (IOException e)
            //{
            //    throw new RuntimeException(e);
            //}
            return new FileStream(path,FileMode.OpenOrCreate,FileAccess.ReadWrite);
        }
    

开发者ID:dotnetcore,项目名称:NPOI,代码行数:30,代码来源:POIDataSamples.cs

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

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