EvilRoslynAnalyzers icon indicating copy to clipboard operation
EvilRoslynAnalyzers copied to clipboard

Feature idea: every number should be a constant in one single class

Open Mrxx99 opened this issue 10 months ago • 1 comments

Magic numbers are evil, therefore a constant should be introduced for each. A codefixer should create a constant for each number that is not. All the constants should be created in one single class called Constants and the created name should be the written name of the number.

E.g.

Console.WriteLine(5);

Becomes

Console.WriteLine(Constants.Five);

Mrxx99 avatar Apr 16 '24 19:04 Mrxx99

Instead of single class with multiple constants, I'd prefere one class per value.

Usage:

Console.WriteLine((new Universe.Mathematics.Numbers.Integers.Five()).IntegerOfFive);

// prints 5.0123
Console.WriteLine((new Universe.Mathematics.Numbers.Decimals.Five.Zero.One.Two.Three()).FloatOfFiveDotZeroOneTwentyThree);

The class shall implement own interface, so mocking and IoC could be easy.

TenCoKaciStromy avatar Apr 17 '24 04:04 TenCoKaciStromy