dotnet/roslyn
IDE0051 should factor in new dependency attributes in .NET 5
オープン
#48,206 opened on 2020/09/30
Area-IDEConcept-Continuous ImprovementFeature - IDE0051help wanted
Repository metrics
- Stars
- (20,414 個のスター)
- PR merge metrics
- (平均マージ 6d 17h) (30d で 256 merged PRs)
説明
Version Used: 3.9.0-1.20480.1+b3c3f4875957e51526000898673291d11708d35b
Steps to Reproduce:
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
class Program
{
static void Main() => new Program().Bar();
[DynamicDependency("Foo")]
private void Bar() => typeof(Program).GetMethod("Foo", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, null);
private void Foo() => Console.WriteLine("Hello");
}
Expected Behavior: .NET 5 adds new attributes that enable dependencies not obvious in the code, e.g. those via reflection, to be used for dead code elimination tools like https://github.com/mono/linker to better understand such dependencies. IDE0051 is such a tool and should ideally respect these attributes, such that in this example, IDE0051 doesn't fire.
Actual Behavior:
IDE0051 fires and suggests deleting the "unused" method:

cc: @eerhardt, @nickcraver