Skip to content

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

Open
@alexmurari

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions