Skip to content

Create Roslyn analyzer for converting runtime Enum.ToString() calls to nameof(Enum) #1296

@NightOwl888

Description

@NightOwl888

Is there an existing issue for this?

  • I have searched the existing issues

Task description

When looking through the codebase, I noticed a few places where we are doing:

field.PutAttribute(legacyKey, LegacyDocValuesType.BYTES_FIXED_DEREF.ToString());

The BYTES_FIXED_DEREF is a compile-time enum value, so it would both be more readable, and save an initial allocation if we changed it to:

field.PutAttribute(legacyKey, nameof(LegacyDocValuesType.BYTES_FIXED_DEREF));

I had ChatGPT sketch up the code for what this analyzer and code fix would look like:

https://chatgpt.com/share/69f41082-6ccc-8323-8639-9d4b6ff906f3

Note that this won't work on runtime values of variables that are declared LegacyDocValuesType, it is only sensible to do this when referencing the enum value directly as in the above example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Task.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions