How to make Resharper format line-wrapped ternary

2019-03-19 01:54发布

问题:

I really want Resharper to format my line-wrapped ternaries in this way

return
    navigator.IsTerminating ?
    navigator.Context :
    navigator.Context.GetSimulatableRelative(new Navigator(navigator));

Can anyone help with this?

回答1:

I don't think there is an out of the box way of doing this. The only way i know to influence how R# formats code is through these settings:

Resharper --> Options... --> Langauges --> C# --> Formatting Style

This doesn't allow you to write your own custom formatting rules though.

If you feel like a challenge then you could write a plugin. There is some docs and an SDK:

  • Developer Docs
  • SDK
  • A video tutorial