| | | 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 | | |
| | | 4 | | using System.Collections.Immutable; |
| | | 5 | | using System.Reflection.Metadata.Ecma335; |
| | | 6 | | |
| | | 7 | | namespace System.Reflection.Metadata |
| | | 8 | | { |
| | | 9 | | public readonly struct StandaloneSignature |
| | | 10 | | { |
| | | 11 | | private readonly MetadataReader _reader; |
| | | 12 | | |
| | | 13 | | // Workaround: JIT doesn't generate good code for nested structures, so use RowId. |
| | | 14 | | private readonly int _rowId; |
| | | 15 | | |
| | | 16 | | internal StandaloneSignature(MetadataReader reader, StandaloneSignatureHandle handle) |
| | 0 | 17 | | { |
| | 0 | 18 | | _reader = reader; |
| | 0 | 19 | | _rowId = handle.RowId; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | private StandaloneSignatureHandle Handle |
| | | 23 | | { |
| | 0 | 24 | | get { return StandaloneSignatureHandle.FromRowId(_rowId); } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets a handle to the signature blob. |
| | | 29 | | /// </summary> |
| | | 30 | | public BlobHandle Signature |
| | | 31 | | { |
| | 0 | 32 | | get { return _reader.StandAloneSigTable.GetSignature(_rowId); } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public MethodSignature<TType> DecodeMethodSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGener |
| | 0 | 36 | | { |
| | 0 | 37 | | var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext); |
| | 0 | 38 | | var blobReader = _reader.GetBlobReader(Signature); |
| | 0 | 39 | | return decoder.DecodeMethodSignature(ref blobReader); |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | public ImmutableArray<TType> DecodeLocalSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGeneric |
| | 0 | 43 | | { |
| | 0 | 44 | | var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext); |
| | 0 | 45 | | var blobReader = _reader.GetBlobReader(Signature); |
| | 0 | 46 | | return decoder.DecodeLocalSignature(ref blobReader); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public CustomAttributeHandleCollection GetCustomAttributes() |
| | 0 | 50 | | { |
| | 0 | 51 | | return new CustomAttributeHandleCollection(_reader, Handle); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Determines the kind of signature, which can be <see cref="SignatureKind.Method"/> or <see cref="SignatureKin |
| | | 56 | | /// </summary> |
| | | 57 | | /// <exception cref="BadImageFormatException">The signature is invalid.</exception> |
| | | 58 | | public StandaloneSignatureKind GetKind() |
| | 0 | 59 | | { |
| | 0 | 60 | | BlobReader blobReader = _reader.GetBlobReader(this.Signature); |
| | 0 | 61 | | SignatureHeader header = blobReader.ReadSignatureHeader(); |
| | | 62 | | |
| | 0 | 63 | | return header.Kind switch |
| | 0 | 64 | | { |
| | 0 | 65 | | SignatureKind.Method => StandaloneSignatureKind.Method, |
| | 0 | 66 | | SignatureKind.LocalVariables => StandaloneSignatureKind.LocalVariables, |
| | 0 | 67 | | _ => throw new BadImageFormatException(), |
| | 0 | 68 | | }; |
| | 0 | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | |