Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class AddPackageFixer : CodeFixProvider
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
if (root == null)
{
return;
}

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
if (semanticModel == null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,20 @@

namespace Microsoft.AspNetCore.Analyzers;

internal record struct ThisAndExtensionMethod(ITypeSymbol thisType, string extensionMethod);
internal readonly struct ThisAndExtensionMethod(ITypeSymbol thisType, string extensionMethod)
{
public ITypeSymbol ThisType { get; } = thisType;
public string ExtensionMethod { get; } = extensionMethod;

public override bool Equals(object obj)
{
return obj is ThisAndExtensionMethod other &&
SymbolEqualityComparer.Default.Equals(ThisType, other.ThisType) &&
ExtensionMethod == other.ExtensionMethod;
}

public override int GetHashCode()
{
return HashCode.Combine(ThisType, ExtensionMethod);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<InternalsVisibleTo Include="Microsoft.AspNetCore.App.Analyzers.Test" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\HashCode.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ public async Task CanFixMissingExtensionMethodForBuilder()

public class MockAddPackageFixer : AddPackageFixer
{
/// <remarks>
/// This static property allows us to verify that the fixer was
/// able to successfully resolve the symbol and call into the
/// package install APIs. This is a workaround for the fact that
/// the package install APIs are not readily mockable. Note: this
/// is not intended for use across test classes.
/// </remarks>
internal static bool Invoked { get; set; }

internal override Task<CodeAction> TryCreateCodeActionAsync(
Document document,
int position,
Expand Down