CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

Resolve symbols early in all analyzers #586

Closed Sergio0694 closed 1 year ago

Sergio0694 commented 1 year ago

context.Compilation.GetTypeByMetadataName

Not so good to do this call here. Better:

context.RegisterCompilationStartAction(context =>
{
    var notifyDataErrorInfoAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.NotifyDataErrorInfoAttribute");
    if (notifyDataErrorInfoAttributeSymbol is null)
    {
        return;
    }

    context.RegisterSymbolAction(context =>
    {
        // Logic goes here.
    }
}

_Originally posted by @Youssef1313 in https://github.com/CommunityToolkit/dotnet/pull/581#discussion_r1084083044_