Skip to content

RCS1085 suggests auto-property for ref-field backed properties #1717

@ovska

Description

@ovska
// before fixer
public readonly ref struct Example(ref int value)
{
    private readonly ref int _value = ref value;
    
    // Use auto-implemented property (RCS1085)
    public int Value
    {
        get => _value;
        set => _value = value;
    }
}

// after fixer
public readonly ref struct Example(ref int value)
{
    // Cannot initialize a by-value variable with a reference (CS8171) and a few other errors
    public int Value { get; set; } = ref value;
}

A regular constructor fails in slightly different ways, but at the end of the day, ref backed properties can't be automatic.

Suggestion: exclude ref field backed properties from this analyzer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions