Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-287749: Use object initialiser - refactoring incorrectly when "new" statements on multiple lines.

$
0
0
Reporter Joel (joellister) Joel (joellister)
Created Jan 13, 2012 3:31:04 PM
Updated Jan 16, 2012 6:15:20 PM
Priority Normal
Type Feature
Fix versions No Fix versions
State Open
Assignee Evgeny Pasynkov (pasynkov)
Subsystem Code Cleanup
Affected versions 6.1
Fixed in build No Fixed in build
Whilst refactoring the following code, I encountered a problem when using the R# "Use object initialiser"

class MySample
{
public void Test()
{
var model = new MyModel();
model.MyProperties = new List<MyProperty>();
model.MyProperties.Add(new MyProperty{ContactId = 1,EmailAddress = "info@test.com"});
model.MyProperties.Add(new MyProperty { ContactId = 2, EmailAddress = "info@test.com" });
}
}

If I move the cursor to the "new" keyword in the line var model = new MyModel(); then hit alt-enter and select "Use object intialiser" the following code is generated, wrongly removing the model.MyProperties.Add(...) lines

public void Test()
{
var model = new MyModel {MyProperties = new List<MyProperty>()};
}


It should do something like this.

public void Test()
{
var model = new MyModel
{
MyProperties = new List<MyProperty>
{
new MyProperty {ContactId = 1, EmailAddress = "info@test.com"},
new MyProperty {ContactId = 2, EmailAddress = "info@test.com"}
}
};
}


I'm using VS2010 and r# version 6.1.37.86

Here are the classes used in the above example

class MyModel
{
public List<MyProperty> MyProperties { get; set; }
}
class MyProperty
{
public int ContactId { get; set; }
public string EmailAddress { get; set; }
}

Regards,

Joel.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>