< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 73
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%220%
GetReader()100%110%
GetReader(...)100%110%
GetContent()0%220%
GetContent(...)0%220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEMemoryBlock.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.Diagnostics;
 6using System.Reflection.Internal;
 7using System.Reflection.Metadata;
 8using System.Runtime.InteropServices;
 9
 10namespace System.Reflection.PortableExecutable
 11{
 12    public readonly struct PEMemoryBlock
 13    {
 14        private readonly AbstractMemoryBlock _block;
 15        private readonly int _offset;
 16
 17        internal PEMemoryBlock(AbstractMemoryBlock block, int offset = 0)
 018        {
 019            Debug.Assert(block != null);
 020            Debug.Assert(offset >= 0 && offset <= block.Size);
 21
 022            _block = block;
 023            _offset = offset;
 024        }
 25
 26        /// <summary>
 27        /// Pointer to the first byte of the block.
 28        /// </summary>
 029        public unsafe byte* Pointer => (_block != null) ? _block.Pointer + _offset : null;
 30
 31        /// <summary>
 32        /// Length of the block.
 33        /// </summary>
 034        public int Length => _block?.Size - _offset ?? 0;
 35
 36        /// <summary>
 37        /// Creates <see cref="BlobReader"/> for a blob spanning the entire block.
 38        /// </summary>
 39        public unsafe BlobReader GetReader()
 040        {
 041            return new BlobReader(Pointer, Length);
 042        }
 43
 44        /// <summary>
 45        /// Creates <see cref="BlobReader"/> for a blob spanning a part of the block.
 46        /// </summary>
 47        /// <exception cref="ArgumentOutOfRangeException">Specified range is not contained within the block.</exception>
 48        public unsafe BlobReader GetReader(int start, int length)
 049        {
 050            BlobUtilities.ValidateRange(Length, start, length, nameof(length));
 051            return new BlobReader(Pointer + start, length);
 052        }
 53
 54        /// <summary>
 55        /// Reads the content of the entire block into an array.
 56        /// </summary>
 57        public ImmutableArray<byte> GetContent()
 058        {
 059            return _block?.GetContentUnchecked(_offset, Length) ?? ImmutableArray<byte>.Empty;
 060        }
 61
 62        /// <summary>
 63        /// Reads the content of a part of the block into an array.
 64        /// </summary>
 65        /// <exception cref="ArgumentOutOfRangeException">Specified range is not contained within the block.</exception>
 66        public ImmutableArray<byte> GetContent(int start, int length)
 067        {
 068            BlobUtilities.ValidateRange(Length, start, length, nameof(length));
 069            return _block?.GetContentUnchecked(_offset + start, length) ?? ImmutableArray<byte>.Empty;
 070        }
 71    }
 72}
 73