Duplicate using directives in multiple files

I have 5 C # files that contain 20 usingdirectives . I want to get rid of code duplication, especially because these 20 using directives logically match. In C or C ++, I would create an additional header file containing these 20 included files. This optional header file acts as a layer and then includes 20 other files at a time.

Unfortunately, I do not know how to do this in C #. Any suggestions?

+4
source share
2 answers

You cannot do this in C #, since C # does not have a preprocessor, and the C # compiler, although it supports some syntax that looks like preprocessor syntax, is processed by the compiler itself, and the compiler does not support include directives.

Also, if even one file actually requires 20 using statements, it sounds to me as if you put too much responsibility in one class. Perhaps this will be better served by refactoring and restructuring the code base, thereby reducing the number of directives required?

. , 20, , " ", 20 ? , .

.

+14

. 20 , 20 . , . , DRY.

+1

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


All Articles