Skip to content

"Generate Equals" refactorings should not include set-only properties #25707

@jhinder

Description

@jhinder

Version Used: VS 15.7 Preview 2 (Roslyn 2.8.0.62716)

Steps to Reproduce:

  1. Copy the class below into a C# source file.
  2. Invoke the Quick Fix menu at the marked location and select either "Generate Equals" or "Generate Equals and GetHashCode".
  3. Make sure SetOnly is marked in the list and press "OK".
class Repro
{
	int SetOnly { set { } }
	$$
}

Expected Behavior: The property is not included in the list, and thus doesn't appear in the generated code.

Actual Behavior: The generated code looks something like this:

public override bool Equals(object obj)
{
	var repro = obj as Repro;
	return repro != null &&
		   this.SetOnly == repro.SetOnly; // Emits two CS0154 errors
}

public override int GetHashCode()
{
	return 257811045 + this.SetOnly.GetHashCode(); // Emits one CS0154 error
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions