C# MemoryStream.GetBuffer的代码示例
通过代码示例来学习C# MemoryStream.GetBuffer方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.GetBuffer是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.GetBuffer() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.GetBuffer() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.GetBuffer的代码示例1 - CreateAssemblyBlob()
using System.IO; private static AssemblyBlob CreateAssemblyBlob(string assemblyName, AssemblyBlob[] references, string text) { var defaultReferences = new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), }; var compilation = CSharpCompilation.Create( assemblyName, new[] { CSharpSyntaxTree.ParseText(text) }, references.Select(r => r.ToMetadataReference()).Concat(defaultReferences), new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); using (var assemblyStream = new MemoryStream()) using (var symbolStream = new MemoryStream()) { var result = compilation.Emit(assemblyStream, symbolStream); Assert.Empty(result.Diagnostics); return new AssemblyBlob(assemblyName, assemblyStream.GetBuffer(), symbolStream.GetBuffer()); } }
开发者ID:aspnet,项目名称:Razor,代码行数:24,代码来源:LoaderTestResources.cs
在CreateAssemblyBlob()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例2 - flushBody()
using System.IO; private void flushBody (bool closing) { using (_bodyBuffer) { var len = _bodyBuffer.Length; if (len > Int32.MaxValue) { _bodyBuffer.Position = 0; var buffLen = 1024; var buff = new byte[buffLen]; var nread = 0; while (true) { nread = _bodyBuffer.Read (buff, 0, buffLen); if (nread <= 0) break; _writeBody (buff, 0, nread); } } else if (len > 0) { _writeBody (_bodyBuffer.GetBuffer (), 0, (int) len); } } if (!closing) { _bodyBuffer = new MemoryStream (); return; } if (_sendChunked) _write (_lastChunk, 0, 5); _bodyBuffer = null; }
开发者ID:ntminer,项目名称:NtMiner,代码行数:38,代码来源:ResponseStream.cs
在flushBody()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例3 - 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的代码示例类中的GetBuffer的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例4 - RemoveTaggedLines()
using System.IO; public void RemoveTaggedLines() { Flush(); // Read and process the stream using spans to avoid any extra buffer copy. var removeLineBytes = _writer.Encoding.GetBytes(FileGeneratorUtilities.RemoveLineTag.ToCharArray()).AsSpan(); var wholeStreamSpan = _stream.GetBuffer().AsSpan().Slice(0, (int)_stream.Length); if (wholeStreamSpan.IndexOf(removeLineBytes) == -1) return; // Early exit when there is no remove line tag in the file. var newLineBytes = _writer.Encoding.GetBytes(Environment.NewLine.ToCharArray()).AsSpan(); var newStream = new MemoryStream((int)_stream.Length); int nextSlice = 0; while (true) { // Looking for end of line var restOfFileSlice = wholeStreamSpan.Slice(nextSlice); int endLineIndex = -1; int endLineMarkerSize = 0; for (int i = 0; i < restOfFileSlice.Length; i++) { byte ch = restOfFileSlice[i]; if (ch == '\r' || ch == '\n') { endLineIndex = nextSlice + i; endLineMarkerSize = 1; if (ch == '\r' && i + 1 < restOfFileSlice.Length && restOfFileSlice[i + 1] == '\n') { endLineMarkerSize = 2; } break; } } if (endLineIndex != -1) { // Check if the line contains the remove line tag. Skip the line if found var lineSlice = wholeStreamSpan.Slice(nextSlice, endLineIndex - nextSlice); if (lineSlice.IndexOf(removeLineBytes) == -1) { newStream.Write(lineSlice); newStream.Write(newLineBytes); } // Advance to next line nextSlice += (lineSlice.Length + endLineMarkerSize); if (nextSlice >= wholeStreamSpan.Length) { Debug.Assert(nextSlice == wholeStreamSpan.Length); break; } } else { // Rest of file. var lineSlice = wholeStreamSpan.Slice(nextSlice); // Check if the line contains the remove line tag. Skip the line if found if (lineSlice.IndexOf(removeLineBytes) == -1) { newStream.Write(lineSlice); // Note: Adding a new line to generate the exact same thing than with original implementation newStream.Write(newLineBytes); } // End of file break; } } Debug.Assert(newStream.Length > 0); var newWriter = new StreamWriter(newStream, _writer.Encoding); _writer.Dispose(); // This will dispose _stream as well. _stream = newStream; _writer = newWriter; }
开发者ID:ubisoft,项目名称:Sharpmake,代码行数:80,代码来源:FileGenerator.cs
在RemoveTaggedLines()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例5 - Encode()
using System.IO; ///
编码。请求/响应 /// /// /// ///public virtual Packet Encode(String action, Int32 code, Packet value) { // 内存流,前面留空8字节用于协议头4字节(超长8字节) var ms = new MemoryStream(); ms.Seek(8, SeekOrigin.Begin); // 请求:action + args // 响应:action + code + result var writer = new BinaryWriter(ms); writer.Write(action); // 异常响应才有code if (code != 0) writer.Write(code); // 参数或结果 var pk = value; if (pk != null) writer.Write(pk.Total); var rs = new Packet(ms.GetBuffer(), 8, (Int32)ms.Length - 8) { Next = pk }; return rs; }
开发者ID:NewLifeX,项目名称:X,代码行数:31,代码来源:JsonEncoder.cs
在Encode()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例6 - GetResourceAsString()
using System.IO; ///
/// Converts an assembly resource into a string. /// /// Theto load the strings from. /// The resource. /// The character encoding to return the resource in. /// /// The public static string GetResourceAsString(this Assembly assembly, string resource, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; using (var ms = new MemoryStream()) { using (Stream manifestResourceStream = assembly.GetManifestResourceStream(resource)) { manifestResourceStream?.CopyTo(ms); } return encoding.GetString(ms.GetBuffer()).Replace('\0', ' ').Trim(); } }. ///
开发者ID:JimBobSquarePants,项目名称:ImageProcessor,代码行数:25,代码来源:AssemblyExtensions.cs
在GetResourceAsString()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.GetBuffer的代码示例7 - TestCommentShowsBox()
using System.IO; [Test] public void TestCommentShowsBox() { XSSFWorkbook wb = new XSSFWorkbook(); wb.CreateSheet(); XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0); XSSFCell cell = (XSSFCell)sheet.CreateRow(0).CreateCell(0); XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFCreationHelper factory = (XSSFCreationHelper)wb.GetCreationHelper(); XSSFClientAnchor anchor = (XSSFClientAnchor)factory.CreateClientAnchor(); anchor.Col1 = cell.ColumnIndex; anchor.Col2 = cell.ColumnIndex + 3; anchor.Row1 = cell.RowIndex; anchor.Row2 = cell.RowIndex + 5; XSSFComment comment = (XSSFComment)drawing.CreateCellComment(anchor); XSSFRichTextString str = (XSSFRichTextString)factory.CreateRichTextString("this is a comment"); comment.String = str; cell.CellComment = comment; XSSFVMLDrawing vml = sheet.GetVMLDrawing(false); CT_Shapetype shapetype = null; ArrayList items = vml.GetItems(); foreach (object o in items) if (o is CT_Shapetype) shapetype = (CT_Shapetype)o; Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.stroked); Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.filled); using (MemoryStream ws = new MemoryStream()) { wb.Write(ws); using (MemoryStream rs = new MemoryStream(ws.GetBuffer())) { wb = new XSSFWorkbook(rs); sheet = (XSSFSheet)wb.GetSheetAt(0); vml = sheet.GetVMLDrawing(false); shapetype = null; items = vml.GetItems(); foreach (object o in items) if (o is CT_Shapetype) shapetype = (CT_Shapetype)o; //wb.Write(new FileStream("comments.xlsx", FileMode.Create)); //using (MemoryStream ws2 = new MemoryStream()) //{ // vml.Write(ws2); // throw new System.Exception(System.Text.Encoding.UTF8.GetString(ws2.GetBuffer())); //} Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.stroked); Assert.AreEqual(NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t, shapetype.filled); } } }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:57,代码来源:TestXSSFVMLDrawing.cs
在TestCommentShowsBox()方法中,MemoryStream的代码示例类中的GetBuffer的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.GetBuffer方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。