Sitelet https://github.com/dotnet/codeformatter/issues/230
Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

CodeFormatter should not rename private fields that are part of an interop type. #230

Description

C# structs that are designed to map to known C++ structures for the purposes of P/Invoke'ing are expected to have names that match the original C++ names. CodeFormatter should not add an "_" to those fields, even if the field's visibility is "private."

Two reasons I might put "private" on such a field:

  • It represents a union field and I choose to hide it and replace them with strongly typed properties that validate or assert the union discriminator.
  • It represents an obscure/dangerous/hard-to-marshal field that I know my library doesn't reference so I choose to mark it NYOB and have the "private" visibility enforce that.

A good rule for deciding whether a struct is an "interop type" might be to check if the author explicitly added the [StructLayout(Sequential/Explicit)] tag the struct.

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