C# MemoryStream.Equals的代码示例
通过代码示例来学习C# MemoryStream.Equals方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.Equals是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.Equals() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.Equals() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.Equals的代码示例1 - CopyWorksheetPreservesPivotTables()
using System.IO; [Test] public void CopyWorksheetPreservesPivotTables() { using (var ms = new MemoryStream()) using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Examples\PivotTables\PivotTables.xlsx"))) using (var wb = new XLWorkbook(stream)) { var ws1 = wb.Worksheet("pvt1"); var copyOfws1 = ws1.CopyTo("CopyOfPvt1"); AssertPivotTablesAreEqual(ws1, copyOfws1); using (var wb2 = new XLWorkbook()) { // We need to copy the source too. Cross workbook references don't work yet. wb.Worksheet("PastrySalesData").CopyTo(wb2); var ws2 = ws1.CopyTo(wb2, "Copy"); AssertPivotTablesAreEqual(ws1, ws2); wb2.SaveAs(ms); } using (var wb2 = new XLWorkbook(ms)) { var ws2 = wb2.Worksheet("Copy"); AssertPivotTablesAreEqual(ws1, ws2); } } void AssertPivotTablesAreEqual(IXLWorksheet ws1, IXLWorksheet ws2) { Assert.AreEqual(ws1.PivotTables.Count(), ws2.PivotTables.Count()); var comparer = new PivotTableComparer(); for (int i = 0; i < ws1.PivotTables.Count(); i++) { var original = ws1.PivotTables.ElementAt(i).CastTo
(); var copy = ws2.PivotTables.ElementAt(i).CastTo (); Assert.AreEqual(ws2, copy.Worksheet); Assert.AreNotEqual(original.Guid, copy.Guid); Assert.IsTrue(comparer.Equals(original, copy)); } } }
开发者ID:ClosedXML,项目名称:ClosedXML,代码行数:48,代码来源:XLWorksheetTests.cs
在CopyWorksheetPreservesPivotTables()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.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()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例3 - UpdateSelectedClipboardContent()
using System.IO; private void UpdateSelectedClipboardContent() { ResetSelected(); if (lvClipboardContentList.SelectedItems.Count > 0) { ListViewItem lvi = lvClipboardContentList.SelectedItems[0]; string format = lvi.Text; if (CurrentDataObject != null) { object data = CurrentDataObject.GetData(format); if (data != null) { try { switch (data) { case MemoryStream ms: if (format.Equals(ClipboardHelpers.FORMAT_PNG, StringComparison.OrdinalIgnoreCase)) { using (Bitmap bmp = new Bitmap(ms)) { Bitmap clonedImage = ClipboardHelpersEx.CloneImage(bmp); LoadImage(clonedImage); } } else if (format.Equals(DataFormats.Dib, StringComparison.OrdinalIgnoreCase)) { Bitmap bmp = ClipboardHelpersEx.ImageFromClipboardDib(ms.ToArray()); LoadImage(bmp); } else if (format.Equals(ClipboardHelpers.FORMAT_17, StringComparison.OrdinalIgnoreCase)) { Bitmap bmp = ClipboardHelpersEx.DIBV5ToBitmap(ms.ToArray()); LoadImage(bmp); } else { LoadText(data.ToString()); } break; case Bitmap bmp: LoadImage(bmp); break; default: LoadText(data.ToString()); break; } } catch (Exception e) { e.ShowError(); } } } } }
开发者ID:ShareX,项目名称:ShareX,代码行数:61,代码来源:ClipboardViewerForm.cs
在UpdateSelectedClipboardContent()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例4 - EmptyModuleShouldAlwaysContainCorLibReference()
using System.IO; [Fact] public void EmptyModuleShouldAlwaysContainCorLibReference() { // Issue #39 (https://github.com/Washi1337/AsmResolver/issues/39) var module = new ModuleDefinition("TestModule"); var corLib = module.CorLibTypeFactory.CorLibScope; using var stream = new MemoryStream(); module.Write(stream); var newModule = ModuleDefinition.FromBytes(stream.ToArray()); var comparer = new SignatureComparer(); Assert.Contains(newModule.AssemblyReferences, reference => comparer.Equals(corLib, reference)); }
开发者ID:Washi1337,项目名称:AsmResolver,代码行数:17,代码来源:ModuleDefinitionTest.cs
在EmptyModuleShouldAlwaysContainCorLibReference()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例5 - ConfirmEqual()
using System.IO; public static void ConfirmEqual(byte[] expected, string[] hexDataLines) { MemoryStream ms = new MemoryStream(hexDataLines.Length * 32 + 32); for (int i = 0; i < hexDataLines.Length; i++) { byte[] lineData = HexRead.ReadFromString(hexDataLines[i]); ms.Write(lineData, 0, lineData.Length); } if (!Array.Equals(expected, ms.ToArray())) { throw new System.Exception("different"); } }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:17,代码来源:RawDataUtil.cs
在ConfirmEqual()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例6 - TestEmptyDocumentBug11744()
using System.IO; [Test] public void TestEmptyDocumentBug11744() { byte[] TestData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; POIFSFileSystem fs = new POIFSFileSystem(); fs.CreateDocument(new MemoryStream(new byte[0]), "Empty"); fs.CreateDocument(new MemoryStream(TestData), "NotEmpty"); MemoryStream output = new MemoryStream(); fs.WriteFileSystem(output); // This line caused the error. fs = new POIFSFileSystem(new MemoryStream(output.ToArray())); DocumentEntry entry = (DocumentEntry)fs.Root.GetEntry("Empty"); Assert.AreEqual(0, entry.Size, "Expected zero size"); byte[] actualReadbackData; actualReadbackData = NPOI.Util.IOUtils.ToByteArray(new DocumentInputStream(entry)); Assert.AreEqual(0, actualReadbackData.Length, "Expected zero read from stream"); entry = (DocumentEntry)fs.Root.GetEntry("NotEmpty"); actualReadbackData = NPOI.Util.IOUtils.ToByteArray(new DocumentInputStream(entry)); Assert.AreEqual(TestData.Length, entry.Size, "Expected size was wrong"); Assert.IsTrue( Arrays.Equals(TestData,actualReadbackData), "Expected different data Read from stream"); }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:27,代码来源:TestEmptyDocument.cs
在TestEmptyDocumentBug11744()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例7 - TestAreDocumentsIdentical()
using System.IO; [Test] public void TestAreDocumentsIdentical() { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dirA = fs.CreateDirectory("DirA"); DirectoryEntry dirB = fs.CreateDirectory("DirB"); DocumentEntry entryA1 = dirA.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); DocumentEntry entryA1b = dirA.CreateDocument("Entry1b", new ByteArrayInputStream(dataSmallA)); DocumentEntry entryA2 = dirA.CreateDocument("Entry2", new ByteArrayInputStream(dataSmallB)); DocumentEntry entryB1 = dirB.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); // Names must match Assert.AreEqual(false, entryA1.Name.Equals(entryA1b.Name)); Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA1b)); // Contents must match Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA2)); // Parents don't matter if contents + names are the same Assert.AreEqual(false, entryA1.Parent.Equals(entryB1.Parent)); Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(entryA1, entryB1)); // Can work with NPOIFS + POIFS //ByteArrayOutputStream tmpO = new ByteArrayOutputStream(); MemoryStream tmpO = new MemoryStream(); fs.WriteFileSystem(tmpO); ByteArrayInputStream tmpI = new ByteArrayInputStream(tmpO.ToArray()); NPOIFSFileSystem nfs = new NPOIFSFileSystem(tmpI); DirectoryEntry dN1 = (DirectoryEntry)nfs.Root.GetEntry("DirA"); DirectoryEntry dN2 = (DirectoryEntry)nfs.Root.GetEntry("DirB"); DocumentEntry eNA1 = (DocumentEntry)dN1.GetEntry(entryA1.Name); DocumentEntry eNA2 = (DocumentEntry)dN1.GetEntry(entryA2.Name); DocumentEntry eNB1 = (DocumentEntry)dN2.GetEntry(entryB1.Name); Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, eNA2)); Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, eNB1)); Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA1b)); Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA2)); Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryA1)); Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryB1)); }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:48,代码来源:TestEntryUtils.cs
在TestAreDocumentsIdentical()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Equals的代码示例8 - TestOK()
using System.IO; [Test] public void TestOK() { byte[] ok = Encoding.UTF8.GetBytes("
Hello There!Tags!"); EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream( new MemoryStream(ok) ); MemoryStream bout = new MemoryStream(); bool going = true; while (going) { byte[] b = new byte[1024]; int r = inp.Read(b); if (r > 0) { bout.Write(b, 0, r); } else { going = false; } } byte[] result = bout.ToArray(); Assert.IsTrue(Arrays.Equals(ok, result)); }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:29,代码来源:TestEvilUnclosedBRFixingInputStream.cs
在TestOK()方法中,MemoryStream的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.Equals方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。