< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 73
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetMemoryBlock()100%110%
GetMemoryBlock(...)0%220%
TryGetUnderlyingStream(...)100%110%
Dispose()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/MemoryBlockProvider.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.Diagnostics.CodeAnalysis;
 5using System.IO;
 6using System.Reflection.PortableExecutable;
 7
 8namespace System.Reflection.Internal
 9{
 10    internal abstract class MemoryBlockProvider : IDisposable
 11    {
 12        /// <summary>
 13        /// Creates and hydrates a memory block representing all data.
 14        /// </summary>
 15        /// <exception cref="IOException">Error while reading from the memory source.</exception>
 16        public AbstractMemoryBlock GetMemoryBlock()
 017        {
 018            return GetMemoryBlockImpl(0, Size);
 019        }
 20
 21        /// <summary>
 22        /// Creates and hydrates a memory block representing data in the specified range.
 23        /// </summary>
 24        /// <param name="start">Starting offset relative to the beginning of the data represented by this provider.</par
 25        /// <param name="size">Size of the resulting block.</param>
 26        /// <exception cref="IOException">Error while reading from the memory source.</exception>
 27        public AbstractMemoryBlock GetMemoryBlock(int start, int size)
 028        {
 29            // Add cannot overflow as it is the sum of two 32-bit values done in 64 bits.
 30            // Negative start or size is handle by overflow to greater than maximum size = int.MaxValue.
 031            if ((ulong)(unchecked((uint)start)) + unchecked((uint)size) > (ulong)this.Size)
 032            {
 033                Throw.ImageTooSmallOrContainsInvalidOffsetOrCount();
 34            }
 35
 036            return GetMemoryBlockImpl(start, size);
 037        }
 38
 39        /// <exception cref="IOException">IO error while reading from the underlying stream.</exception>
 40        protected abstract AbstractMemoryBlock GetMemoryBlockImpl(int start, int size);
 41
 42        /// <summary>
 43        /// Gets the <see cref="Stream"/> backing the <see cref="MemoryBlockProvider"/>, if there is one.
 44        /// </summary>
 45        /// <remarks>
 46        /// It is the caller's responsibility to use <paramref name="stream"/> only
 47        /// while locking on <paramref name="streamGuard"/>, and not read outside the
 48        /// bounds defined by <paramref name="imageStart"/> and <paramref name="imageSize"/>.
 49        /// </remarks>
 50        public virtual bool TryGetUnderlyingStream([NotNullWhen(true)] out Stream? stream, out long imageStart, out int 
 051        {
 052            stream = null;
 053            imageStart = 0;
 054            imageSize = 0;
 055            streamGuard = null;
 056            return false;
 057        }
 58
 59        /// <summary>
 60        /// The size of the data.
 61        /// </summary>
 62        public abstract int Size { get; }
 63
 64        protected abstract void Dispose(bool disposing);
 65
 66        public void Dispose()
 067        {
 068            Dispose(disposing: true);
 069            GC.SuppressFinalize(this);
 070        }
 71    }
 72}
 73