Transform optional parameters to class with object initializer

When transforming parameters to class, is it possible for the constructor of the class created to only have the required parameters and when the usages are refactored there calls use object initializer syntax where the value being passed through does not match the parameter default 

 

At the moment its seems the entire parameter list goes in to the constructor meaning calls are not cleaner, even if there is an existing way to do this across multiple steps id be keen to hear it. . 

 

void Main()
{

//Original call 
Foo(true,"bar",string.Empty,string.Empty,true);

//becomes this
Foo(new InFoo(true, "bar") {op3 = true});

}

//origonal method
public void Foo(bool getBar, string barName, string optinal1 = "", string optional2 = "",bool op3 = false){
...
}

//transformed parameters
public class InFoo{
public bool GetBar { get; set; }
public string BarName {get;set;}
public string optinal1 {get;set;}
public string optional2 {get;set;}
public bool op3 { get; set; }
public InFoo(bool getBar, string barName){
GetBar = getBar;
BarName = barName;
}
}

0
1 comment

Hi Tyron,

Thank you for your request. 

Unfortunately, Rider does not have this functionality, but here is a filed feature request: https://youtrack.jetbrains.com/issue/RIDER-43089.

Please feel free to vote for it to subscribe for updates.

 

Kind regards,

Sofia.

0

Please sign in to leave a comment.