Reporter | Daniel Rigby (CodeM0nkey) |
---|---|
Created | Apr 19, 2012 1:16:31 AM |
Updated | Apr 19, 2012 1:18:04 AM |
Priority | Normal |
Type | Bug |
Fix versions | No Fix versions |
State | Submitted |
Assignee | Alexey Kuptsov (alexey.kuptsov) |
Subsystem | Quick Fixes |
Affected versions | 6.1.1 |
Fixed in build | No Fixed in build |
Applying the "Use object initializer" Quick Fix to code where the property being assigned to is accessed after the set causes that code to be deleted.
This is extremely problematic as a user may not notice the deletion and the code will still continue to compile.
Example:
In the above code, ReSharper will offer the "Use object initializer" Quick Fix on the new in var testClass = new TestClass();
Applying the quick fix results in the following code:
ReSharper has silently deleted the following two lines:
I have attached a small project demonstrating this behavior.
Thanks.
This is extremely problematic as a user may not notice the deletion and the code will still continue to compile.
Example:
public class TestClass { public List<string> MyProperty { get; set; } }
var testClass = new TestClass(); testClass.MyProperty = new List<string>(); testClass.MyProperty.Add("string1"); testClass.MyProperty.Add("string2"); Console.WriteLine(string.Join(",",testClass.MyProperty));
In the above code, ReSharper will offer the "Use object initializer" Quick Fix on the new in var testClass = new TestClass();
Applying the quick fix results in the following code:
var testClass = new TestClass { MyProperty = new List<string>() }; Console.WriteLine(string.Join(",",testClass.MyProperty));
ReSharper has silently deleted the following two lines:
testClass.MyProperty.Add("string1"); testClass.MyProperty.Add("string2");
I have attached a small project demonstrating this behavior.
Thanks.