Skip to content

Support field keyword #2

@datacute

Description

@datacute

C#13 has (as a preview feature) the field contextual keyword that can be used instead of generating backing fields.
This should be supported in Datacute.EmbeddedResourcePropertyGenerator

Since it is possible to implement two partial methods, and in those implementations it is possible to access other backing fields (the property's own backing field is already accessible by ref), then getting rid of those backing fields would be a breaking change.

Options:

  1. The field keyword could be used if the SpecifiedLanguageVersion is Preview and a configuration setting could be used to generate backing fields if required for backwards compatibility. This has the problem that if the keyword is supported in C#14, it wouldn't get used unless the language version was still Preview. Additionally, if the feature becomes unavailable in a future language version, the code would break, and the configuration would need to be added.
  2. A configuration setting could be used to indicate that the field keyword should be used. This has the problem that if the preview feature changes or isn't included in future language versions, the code would break (easily fixable by removing the configuration).

Given it is a preview feature, option 2 to explicitly opt in, is a better option.

It would also be helpful to flag the generated properties as obsolete/deprecated, so that they can be removed (depending on language version) once the field keyword is no longer a preview feature. At that future time a list of unsupported language versions can be checked, and used to trigger generation of the backing fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions