dotnet / dotnet/linker

Linker should warn about usage of MakeGenericType/MakeGenericMethod

Open
#2,198 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

When using MakeGenericType and MakeGenericMethod trimmer should warn if the callable method is known and is annotated with RequiresUnreferencedCode. For example:
```C#
class GenericWithConstraint where T : new() {
public static void Generic (T toDisplay) { }
}

class ClassWithRequiresUnreferencedCodeOnConstructor {
[RequiresUnreferencedCode ("Message for --ClassWithRequiresUnreferencedCodeOnCostructor--")]
void ClassWithRequiresUnreferencedCodeOnCostructor () { }
}
static void Main () {
Type generic = typeof (GenericWithConstraint<>);
Type constructed = generic.MakeGenericType (typeof (ClassWithRequiresUnreferencedCodeOnConstructor));
}
```
In this case the generic class has the new constraint and the type ClassWithRequiresUnreferencedCodeOnConstructor is recognized inside the ReflectionMethodBodyScanner. Trimmer should be able to understand that the constructor will be called and since is annotated produce a warning.

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.