My code can go on 8 branches. Those. For example, the same method should take 2 parameters of type Encoding, only the first overload works with System.Text.Encoding.ASCII and System.Text.Encoding.Unicode, and the second with System.Text.Encoding.UTF8 and System.Text. Encoding.Unicode. How to implement such a construction without a cloud if-s or switch-case?

  • 2
    overload will not work, because your methods will have the same signature, and for overloaded methods the signature must be different. Read more here.stackoverflow.com/a/490768/198316 - rdorn
  • worth adding sample code. - Grundy
  • @rdorn and how then to implement without using if and switch? - dennismeister
  • And what they do not suit you? Specifically in this case in any way. Add what you want to achieve with these manipulations and how you tried to do it, then you can think about how to do it, with telepathy today I don’t really =). - rdorn
  • one
    Maybe we should do two methods? Something like MethodAsciiUnicode and MethodUtf8Unicode . - Alexander Petrov

1 answer 1

The same Fowler advises to get rid of switch and if using polymorphism (here's an example https://refactoring.guru/ru/replace-conditional-with-polymorphism ). Maybe this is your option.