< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 60
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetReader()100%110%
GetStream()100%110%
GetContentUnchecked(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/AbstractMemoryBlock.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Immutable;
 5using System.IO;
 6using System.Reflection.Metadata;
 7
 8namespace System.Reflection.Internal
 9{
 10    /// <summary>
 11    /// Represents a disposable blob of memory accessed via unsafe pointer.
 12    /// </summary>
 13    internal abstract class AbstractMemoryBlock : IDisposable
 14    {
 15        /// <summary>
 16        /// Pointer to the underlying data (not valid after disposal).
 17        /// </summary>
 18        public abstract unsafe byte* Pointer { get; }
 19
 20        /// <summary>
 21        /// Size of the block.
 22        /// </summary>
 23        public abstract int Size { get; }
 24
 025        public unsafe BlobReader GetReader() => new BlobReader(Pointer, Size);
 26
 27        /// <summary>
 28        /// Creates a new stream wrapping the block's memory.
 29        /// </summary>
 030        public unsafe Stream GetStream() => new UnmanagedMemoryStream(Pointer, Size);
 31
 32        /// <summary>
 33        /// Returns the content of the entire memory block.
 34        /// </summary>
 35        /// <remarks>
 36        /// Does not check bounds.
 37        ///
 38        /// Only creates a copy of the data if they are not represented by a managed byte array,
 39        /// or if the specified range doesn't span the entire block.
 40        /// </remarks>
 41        public virtual unsafe ImmutableArray<byte> GetContentUnchecked(int start, int length)
 042        {
 043            var result = new ReadOnlySpan<byte>(Pointer + start, length).ToImmutableArray();
 044            GC.KeepAlive(this);
 045            return result;
 046        }
 47
 48        /// <summary>
 49        /// Disposes the block.
 50        /// </summary>
 51        /// <remarks>
 52        /// The operation is idempotent, but must not be called concurrently with any other operations on the block.
 53        ///
 54        /// Using the block after dispose is an error in our code and therefore no effort is made to throw a tidy
 55        /// ObjectDisposedException and null ref or AV is possible.
 56        /// </remarks>
 57        public abstract void Dispose();
 58    }
 59}
 60