Skip to content

Add an Analyzer to recommend using DIM properties with IHeaderDictionary instead of indexer #44116

@JamesNK

Description

@JamesNK

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

IHeaderDictionary has DIM properties for many commonly used headers: https://github.com/dotnet/aspnetcore/blob/ff2148be7592be83f1f88e2f372ef04f02fdfdb8/src/Http/Http.Features/src/IHeaderDictionary.Keyed.cs

Describe the solution you'd like

An analyzer that looks for indexer use with a name that matches a property.

e.g.

if (request.Headers["Content-Type"] == "application/json")
{
    // ....
}

After change (could be done via a fixer):

if (request.Headers.ContentType == "application/json")
{
    // ....
}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzerIndicates an issue which is related to analyzer experiencearea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions