Skip to content

"Use auto properties" code fix produces invalid code for explicitly implemented interface properties #23735

@yaakov-h

Description

@yaakov-h

Version Used:
Microsoft Visual Studio Enterprise 2017 Preview
Version 15.6.0 Preview 1.0

Steps to Reproduce:

  1. Load the following code in the editor:
namespace RoslynSandbox
{
	public interface IFoo
	{
		object Bar { get; }
	}

	class Foo : IFoo
	{
		public Foo(object bar)
		{
			this.bar = bar;
		}

		readonly object bar;

		object IFoo.Bar
		{
			get { return bar; }
		}
	}
}
  1. Note that line 15 (readonly object bar;) is greyed out.
  2. Click on line 15
  3. Select the lightbulb
  4. Select "Use auto properties"

Expected Behavior:

The code fix should either produce workable code, or not be offered.

Actual Behavior:

The resulting code is invalid and does not compile:

namespace RoslynSandbox
{
	public interface IFoo
	{
		object Bar { get; }
	}

	class Foo : IFoo
	{
		public Foo(object bar)
		{
			this.RoslynSandbox.IFoo.Bar = bar;
		}

		object IFoo.Bar { get; }
	}
}

Metadata

Metadata

Assignees

Labels

Area-IDEBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

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