Aaronontheweb / EvilRoslynAnalyzers

Has your boss gone insane and banned LINQ at work? Why stop there - use this Roslyn Analyzer to ban extension methods altogether!
https://www.reddit.com/r/dotnet/comments/1c4hz1z/linq_forbidden/
Apache License 2.0
31 stars 2 forks source link

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

Open Mrxx99 opened 4 months ago

Mrxx99 commented 4 months ago

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);
TenCoKaciStromy commented 4 months ago

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.