Skip to content

Cleanup CA1305 analyzer to correctly compare method symbols #6052

@mavasani

Description

@mavasani

NOTE: We ideally don't recommend comparing method names to identify if the expected method is being called. Instead you should fetch the expected method symbol on the guidType named type symbol in the compilation start action and directly compare invocationOperation.TargetMethod and that well-known method symbol. However, I see that this analyzer already follows the pattern similar to the one you followed here, so I won't block your PR on this:

private static bool IsValidToStringCall(IInvocationOperation invocationOperation, ImmutableHashSet<INamedTypeSymbol> invariantToStringTypes,
INamedTypeSymbol? dateTimeType, INamedTypeSymbol? dateTimeOffsetType, INamedTypeSymbol? timeSpanType)
{
var targetMethod = invocationOperation.TargetMethod;
if (targetMethod.Name != "ToString")
{
return false;
}

I'll open a tracking issue to clean this up in a follow-up PR.

Originally posted by @mavasani in #6000 (comment)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions