Skip to content

Commit

Permalink
Exclude anonymous types from MA0150
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Jan 2, 2024
1 parent b06406f commit 4e52050
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ private void AnalyzeExpression(DiagnosticReporter reporter, IOperation operation
if (actualType is null)
return;

if (actualType.IsAnonymousType)
return;

if (actualType.IsSealed) // Method cannot be overridden
{
if (!OverrideToString(actualType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ public async Task Interpolation_Enum()
var sourceCode = """
var statusCode = System.Net.HttpStatusCode.OK;
_ = $"{statusCode}";
""";
await CreateProjectBuilder()
.WithSourceCode(sourceCode)
.ValidateAsync();
}

[Fact]
public async Task Interpolation_AnonymousType()
{
var sourceCode = """
var obj = new { FirstName = "" };
_ = $"{obj}";
""";
await CreateProjectBuilder()
.WithSourceCode(sourceCode)
Expand Down

0 comments on commit 4e52050

Please sign in to comment.