| | | 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 EventDefinition |
| | | 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 EventDefinition(MetadataReader reader, EventDefinitionHandle handle) |
| | 0 | 17 | | { |
| | 0 | 18 | | _reader = reader; |
| | 0 | 19 | | _rowId = handle.RowId; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | private EventDefinitionHandle Handle |
| | | 23 | | { |
| | 0 | 24 | | get { return EventDefinitionHandle.FromRowId(_rowId); } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public StringHandle Name |
| | | 28 | | { |
| | | 29 | | get |
| | 0 | 30 | | { |
| | 0 | 31 | | return _reader.EventTable.GetName(Handle); |
| | 0 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public EventAttributes Attributes |
| | | 36 | | { |
| | | 37 | | get |
| | 0 | 38 | | { |
| | 0 | 39 | | return _reader.EventTable.GetFlags(Handle); |
| | 0 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public EntityHandle Type |
| | | 44 | | { |
| | | 45 | | get |
| | 0 | 46 | | { |
| | 0 | 47 | | return _reader.EventTable.GetEventType(Handle); |
| | 0 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public CustomAttributeHandleCollection GetCustomAttributes() |
| | 0 | 52 | | { |
| | 0 | 53 | | return new CustomAttributeHandleCollection(_reader, Handle); |
| | 0 | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Returns a handle to the type that declares this event. |
| | | 58 | | /// </summary> |
| | | 59 | | public TypeDefinitionHandle GetDeclaringType() |
| | 0 | 60 | | { |
| | 0 | 61 | | return _reader.GetDeclaringType(Handle); |
| | 0 | 62 | | } |
| | | 63 | | |
| | | 64 | | public EventAccessors GetAccessors() |
| | 0 | 65 | | { |
| | 0 | 66 | | int adder = 0; |
| | 0 | 67 | | int remover = 0; |
| | 0 | 68 | | int fire = 0; |
| | 0 | 69 | | ImmutableArray<MethodDefinitionHandle>.Builder? other = null; |
| | | 70 | | |
| | | 71 | | ushort methodCount; |
| | 0 | 72 | | int firstRowId = _reader.MethodSemanticsTable.FindSemanticMethodsForEvent(Handle, out methodCount); |
| | 0 | 73 | | for (ushort i = 0; i < methodCount; i++) |
| | 0 | 74 | | { |
| | 0 | 75 | | int rowId = firstRowId + i; |
| | 0 | 76 | | switch (_reader.MethodSemanticsTable.GetSemantics(rowId)) |
| | | 77 | | { |
| | | 78 | | case MethodSemanticsAttributes.Adder: |
| | 0 | 79 | | adder = _reader.MethodSemanticsTable.GetMethod(rowId).RowId; |
| | 0 | 80 | | break; |
| | | 81 | | |
| | | 82 | | case MethodSemanticsAttributes.Remover: |
| | 0 | 83 | | remover = _reader.MethodSemanticsTable.GetMethod(rowId).RowId; |
| | 0 | 84 | | break; |
| | | 85 | | |
| | | 86 | | case MethodSemanticsAttributes.Raiser: |
| | 0 | 87 | | fire = _reader.MethodSemanticsTable.GetMethod(rowId).RowId; |
| | 0 | 88 | | break; |
| | | 89 | | |
| | | 90 | | case MethodSemanticsAttributes.Other: |
| | 0 | 91 | | other ??= ImmutableArray.CreateBuilder<MethodDefinitionHandle>(); |
| | | 92 | | |
| | 0 | 93 | | other.Add(_reader.MethodSemanticsTable.GetMethod(rowId)); |
| | 0 | 94 | | break; |
| | | 95 | | } |
| | 0 | 96 | | } |
| | | 97 | | |
| | 0 | 98 | | var otherAccessors = other?.ToImmutable() ?? ImmutableArray<MethodDefinitionHandle>.Empty; |
| | 0 | 99 | | return new EventAccessors(adder, remover, fire, otherAccessors); |
| | 0 | 100 | | } |
| | | 101 | | } |
| | | 102 | | } |
| | | 103 | | |