Object initializer formatting

Hi,

When I auto-format my documents using Rider, object initializers are put on the same line, breaking at the max character limit for each line, like so:

new PaymentMethod() {
CustomerID = customerId, PaymentProviderID = paymentProviderId, ExpiryDate = paymentExpiryDate,
FullName = fullName, Issuer = paymentIssuer, PaymentData = paymentData,
PaymentMethodType = paymentMethodType, Status = status, StatusText = statusText, RefKey = refKey
};

I'd like Rider to format it like this instead. In fact, this issue seems to be general and not only with object initializers:

new PaymentMethod() {
CustomerID = customerId,
PaymentProviderID = paymentProviderId,
ExpiryDate = paymentExpiryDate,
FullName = fullName,
Issuer = paymentIssuer,
PaymentData = paymentData,
PaymentMethodType = paymentMethodType,
Status = status,
StatusText = statusText,
RefKey = refKey
};
1 comment
Comment actions Permalink

Hi Emil Holst Petersen,

The settings that help to achieve the behavior you need are at File | Settings | Editor | Code Style | C# -> Line Breaks and Wrapping -> Arrangement of Initializers. You need to switch off `Keep existing arrangement...` and set  `Wrap object and collection initializer` to `Chop always`. 

Hope this helps! Sorry for the late reply.

 

0

Please sign in to leave a comment.