Conversion class extension (extension methods and Parital class)

I am creating a conversion class for the frequency, and I wanted my team to be able to add additional conversions when they are needed.

Frequency myFrequency = new Frequency(100, MHz);
double value = myFrequency.InKhz();

The source code for the class will not be included in future projects, so I will either have to have a class, or a partial class, or additional transformations must be extensions. An example would be adding a conversion to GHz

myFrequency.InGHz()

What is the best way to do this?

Update: after reading Randolpho's answer, I move on to the extension method. Since time allows the extensions to roll into the base code, but I did not want other team members to wait for updated assemblies, and this allows them to move on to the next task faster.

+3
3

, . , .

, , , , ; , .

+3

. , , .

+1

, , , , . , , , "" langauge, .

Otherwise, extension methods are likely to be your best option, but they will need to recompile + the new library anytime you want to add new conversions.

0
source

Source: https://habr.com/ru/post/1713260/


All Articles