|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Collections.Generic; |
5 | 6 | using System.Reflection; |
6 | 7 | using System.Reflection.Metadata; |
@@ -101,6 +102,23 @@ static void AddInteropAllocatedType(NodeFactory factory, DependencyList dependen |
101 | 102 | dependencies.Add(factory.ConstructedType((EcmaType)method.OwningType), "Type with a kept constructor"); |
102 | 103 | } |
103 | 104 |
|
| 105 | + var ecmaOwningType = (EcmaType)_module.GetObject(declaringType); |
| 106 | + if (ecmaOwningType.IsDelegate) |
| 107 | + { |
| 108 | + ReadOnlySpan<byte> methodPairName = default; |
| 109 | + if (reader.StringComparer.Equals(methodDef.Name, "BeginInvoke")) |
| 110 | + methodPairName = "EndInvoke"u8; |
| 111 | + else if (reader.StringComparer.Equals(methodDef.Name, "EndInvoke")) |
| 112 | + methodPairName = "BeginInvoke"u8; |
| 113 | + |
| 114 | + if (methodPairName.Length > 0) |
| 115 | + { |
| 116 | + var pairMethod = ecmaOwningType.GetMethod(methodPairName, null) as EcmaMethod; |
| 117 | + if (pairMethod != null) |
| 118 | + dependencies.Add(factory.MethodDefinition(_module, pairMethod.Handle), "Delegate BeginInvoke/EndInvoke pair"); |
| 119 | + } |
| 120 | + } |
| 121 | + |
104 | 122 | // TODO-SIZE: Property/event metadata is not strictly necessary for accessor method calls — |
105 | 123 | // it's only needed for reflection and debugger scenarios. We could skip keeping property/event |
106 | 124 | // rows when we know they won't be accessed via reflection, producing smaller output. |
|
0 commit comments