< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 56
Coverable lines: 56
Total lines: 105
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 32
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetConstantTypeCode(...)0%28280%
SerializeRowCounts(...)0%440%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/MetadataWriterUtilities.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;
 6
 7namespace System.Reflection.Metadata.Ecma335
 8{
 9    internal static class MetadataWriterUtilities
 10    {
 11        public static SignatureTypeCode GetConstantTypeCode(object? value)
 012        {
 013            if (value == null)
 014            {
 15                // The encoding of Type for the nullref value for FieldInit is ELEMENT_TYPE_CLASS with a Value of a zero
 016                return (SignatureTypeCode)0x12; // TODO
 17            }
 18
 019            Debug.Assert(!value.GetType().GetTypeInfo().IsEnum);
 20
 21            // Perf: Note that JIT optimizes each expression val.GetType() == typeof(T) to a single register comparison.
 22            // Also the checks are sorted by commonality of the checked types.
 23
 024            if (value.GetType() == typeof(int))
 025            {
 026                return SignatureTypeCode.Int32;
 27            }
 28
 029            if (value.GetType() == typeof(string))
 030            {
 031                return SignatureTypeCode.String;
 32            }
 33
 034            if (value.GetType() == typeof(bool))
 035            {
 036                return SignatureTypeCode.Boolean;
 37            }
 38
 039            if (value.GetType() == typeof(char))
 040            {
 041                return SignatureTypeCode.Char;
 42            }
 43
 044            if (value.GetType() == typeof(byte))
 045            {
 046                return SignatureTypeCode.Byte;
 47            }
 48
 049            if (value.GetType() == typeof(long))
 050            {
 051                return SignatureTypeCode.Int64;
 52            }
 53
 054            if (value.GetType() == typeof(double))
 055            {
 056                return SignatureTypeCode.Double;
 57            }
 58
 059            if (value.GetType() == typeof(short))
 060            {
 061                return SignatureTypeCode.Int16;
 62            }
 63
 064            if (value.GetType() == typeof(ushort))
 065            {
 066                return SignatureTypeCode.UInt16;
 67            }
 68
 069            if (value.GetType() == typeof(uint))
 070            {
 071                return SignatureTypeCode.UInt32;
 72            }
 73
 074            if (value.GetType() == typeof(sbyte))
 075            {
 076                return SignatureTypeCode.SByte;
 77            }
 78
 079            if (value.GetType() == typeof(ulong))
 080            {
 081                return SignatureTypeCode.UInt64;
 82            }
 83
 084            if (value.GetType() == typeof(float))
 085            {
 086                return SignatureTypeCode.Single;
 87            }
 88
 089            throw new ArgumentException(SR.Format(SR.InvalidConstantValueOfType, value.GetType()), nameof(value));
 090        }
 91
 92        internal static void SerializeRowCounts(BlobBuilder writer, ImmutableArray<int> rowCounts)
 093        {
 094            for (int i = 0; i < rowCounts.Length; i++)
 095            {
 096                int rowCount = rowCounts[i];
 097                if (rowCount > 0)
 098                {
 099                    writer.WriteInt32(rowCount);
 0100                }
 0101            }
 0102        }
 103    }
 104}
 105