Skip to content

Commit

Permalink
MA0150 Skip ToString on anonymous types
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Jan 5, 2024
1 parent 4e52050 commit 86c9051
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void AnalyzeInterpolation(OperationAnalysisContext context)
public void AnalyzeInvocation(OperationAnalysisContext context)
{
var operation = (IInvocationOperation)context.Operation;
if (operation.Instance?.Type?.IsAnonymousType is true)
return;

if (IsDefaultToString(operation.TargetMethod))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ await CreateProjectBuilder()
.ValidateAsync();
}

[Fact]
public async Task ToString_AnonymousType()
{
var sourceCode = """
new { FirstName = "" }.ToString();
""";
await CreateProjectBuilder()
.WithSourceCode(sourceCode)
.ValidateAsync();
}

[Fact]
public async Task Interpolation_ReproCachingIssue()
{
Expand Down

0 comments on commit 86c9051

Please sign in to comment.