dotnet / dotnet/linker

Track MethodInfo, PropertyInfo, and FieldInfo through reflection uses

Open
#3,037 4 comments 0 reactions 0 assignees View on GitHub
proposal
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

For codebases that use reflection extensively, this could simplify transitioning to trim compatibility.

For example, EFCore.Sqlite has this code:
```C#
var currentAppData = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime")
?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET")
?.GetRuntimeProperty("Current")?.GetValue(null);
var localFolder = currentAppData?.GetType()
.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
var localFolderPath = (string?)localFolder?.GetType()
.GetRuntimeProperty("Path")?.GetValue(localFolder);
```

This can technically be statically analyzed, and we know the exact types we need: `Windows.Storage.ApplicationData`, `Windows.Storage.ApplicationData.Current`, the type of `Windows.Storage.ApplicationData.Current`, and its property `LocalFolder`, the type of `LocalFolder`, and its property `Path`.

In addition, we may be able to make `MethodInfo.MakeGenericMethod` AOT-Friendly if we know to keep the method in its generic form and the type being made generic.

Related to https://github.com/dotnet/linker/issues/2482

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.