Which code structure is optimal for C# libraries specialized on constants? [closed]

2 weeks ago 25
ARTICLE AD BOX

I have library fundamental-constants for TypeScript/JavaScript. As it follows from the library name, it is specialized on constants. But what is important is how the source code organized. Basically, there is the single file per constant (example), but even if it was multiple constants per file as below, the optimization technologies like Webpack's tree shaking still works. Thank to such technologies, the unused constants will not be included to output JavaScript code.

export const MINIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS: number = 3; export const MAXIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS: number = 320;

Now about C#. How to organize the source code of similar library optimally for C#? Ideally, the unused constants must not be included to output code. If it is impossible, the unused constants must not be loaded to RAM.

AFAIK, in C# I can not create the constants outside of classes/structs/records. The grouping of variables like below is best that possible?

namespace Constants; public record Email { public const sbyte MINIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS = 3; public const sbyte MAXIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS = 320; }

Will MAXIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS constant be loaded if just MINIMAL_CHARACTERS_COUNT_OF_EMAIL_ADDRESS be used?

Read Entire Article