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 // See the LICENSE file in the project root for more information.
4 
5 using System.Diagnostics;
6 using System.Reflection.Metadata.Ecma335;
7 
8 namespace System.Reflection.Metadata
9 {
10     public readonly struct TypeSpecification
11     {
12         private readonly MetadataReader _reader;
13 
14         // Workaround: JIT doesn't generate good code for nested structures, so use RowId.
15         private readonly int _rowId;
16 
TypeSpecificationSystem.Reflection.Metadata.TypeSpecification17         internal TypeSpecification(MetadataReader reader, TypeSpecificationHandle handle)
18         {
19             Debug.Assert(reader != null);
20             Debug.Assert(!handle.IsNil);
21 
22             _reader = reader;
23             _rowId = handle.RowId;
24         }
25 
26         private TypeSpecificationHandle Handle
27         {
28             get { return TypeSpecificationHandle.FromRowId(_rowId); }
29         }
30 
31         public BlobHandle Signature
32         {
33             get { return _reader.TypeSpecTable.GetSignature(Handle); }
34         }
35 
DecodeSignatureSystem.Reflection.Metadata.TypeSpecification36         public TType DecodeSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGenericContext> provider, TGenericContext genericContext)
37         {
38             var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext);
39             var blobReader = _reader.GetBlobReader(Signature);
40             return decoder.DecodeType(ref blobReader);
41         }
42 
GetCustomAttributesSystem.Reflection.Metadata.TypeSpecification43         public CustomAttributeHandleCollection GetCustomAttributes()
44         {
45             return new CustomAttributeHandleCollection(_reader, Handle);
46         }
47     }
48 }
49