Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
var mdManager = (UsageBasedMetadataManager)factory.MetadataManager;
if (_type.IsDelegate)
{
// A delegate type metadata is rather useless without the Invoke method.
// If someone reflects on a delegate, chances are they're going to look at the signature.
// We've decided as a policy that delegate Invoke methods will be generated in full.
// The libraries (e.g. System.Linq.Expressions) have trimming warning suppressions
// in places where they assume IL-level trimming (where the method cannot be removed).
// We ask for a full reflectable method with its method body instead of just the
// metadata.
var invokeMethod = _type.GetMethod("Invoke", null);
if (!mdManager.IsReflectionBlocked(invokeMethod))
dependencies.Add(factory.MethodMetadata(invokeMethod), "Delegate invoke method metadata");
dependencies.Add(factory.ReflectableMethod(invokeMethod), "Delegate invoke method");
}

if (_type.IsEnum)
Expand Down
15 changes: 15 additions & 0 deletions src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Reflection;
Expand All @@ -31,6 +32,7 @@ private static int Main()
TestVirtualDelegateTargets.Run();
TestRunClassConstructor.Run();
TestFieldMetadata.Run();
TestLinqInvocation.Run();
#if !OPTIMIZED_MODE_WITHOUT_SCANNER
TestContainment.Run();
TestInterfaceMethod.Run();
Expand Down Expand Up @@ -1859,6 +1861,19 @@ public static void Run()
}
}

class TestLinqInvocation
{
delegate void RunMeDelegate();

static void RunMe() { }

public static void Run()
{
Expression<Action<RunMeDelegate>> ex = (RunMeDelegate m) => m();
ex.Compile()(RunMe);
}
}

class TestRunClassConstructor
{
static class TypeWithNoStaticFieldsButACCtor
Expand Down