Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA1859 shouldn't recommend upgrading to an anonymous type #7504

Open
alexmurari opened this issue Dec 13, 2024 · 0 comments · May be fixed by #7505
Open

CA1859 shouldn't recommend upgrading to an anonymous type #7504

alexmurari opened this issue Dec 13, 2024 · 0 comments · May be fixed by #7505

Comments

@alexmurari
Copy link

alexmurari commented Dec 13, 2024

Analyzer

Diagnostic ID: CA1859: Use concrete types when possible for improved performance

Analyzer source

SDK: 9.0.101

Describe the bug

When a method's return type is object and the returned value is an anonymous type (new { Name = "Alex" }) the analyzer suggests changing the method's return type from object to <anonymous type: string Name>. Of course, this return type is invalid.

Steps To Reproduce

Console.WriteLine(BuildObject());

private static object BuildObject() // Triggers CA1859
{
    var outputData = new
    {
        Name = "Alex"
    };

    return outputData;
}

Expected behavior

Shouldn't trigger the CA1859 rule.

Actual behavior

Triggers the CA1859 rule.

@alexmurari alexmurari changed the title CA1859 shouldn't be triggered by anonymous types CA1859 shouldn't recommend upgrading to an anonymous type Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant