Automatically use object initializers during code cleanup

Answered

Is it possible to configure R# so that object initializers are automatically used during a code cleanup?

Example:

myParam = new SqlParameter();
myParam.ParameterName = "email";
myParam.SqlDbType = SqlDbType.NVarChar;
myParam.Value = user.Email;
cmd.Parameters.Add(myParam);

I want this during a code cleanup automatically reformatted to:

myParam = new SqlParameter
{
    ParameterName = "email",
    SqlDbType = SqlDbType.NVarChar,
    Value = user.Email
};
cmd.Parameters.Add(myParam);

Right now I have to do this manually in a large files.

2 comments
Comment actions Permalink

Hello

Has this feature been added in ReSharper? I've searched the settings, I couldn't find anything that would allow that.

Best regards

0
Comment actions Permalink

Hello Armand,

 

Currently, there's no such option, please refer to the following feature request - https://youtrack.jetbrains.com/issue/RSRP-442195.

Thank you.

0

Please sign in to leave a comment.