Using directives to declare a pseudo-type in C #

I inherited some source code that I am just starting to dig, but I found that the previous owner used some directive usingas an alias for List<T>, but I have never seen this particular approach before.

namespace MyNamespace
{
    using pType1 = List<type1>;
    using pType2 = List<List<type1>>;

     // classes here
}

Both of these elements are used quite heavily inside the code and are also return types from several key methods in the code. I get what he tried to accomplish using a simple name, not repeating List<type1>it List<List<type1>>over and over again. I am discussing whether it is necessary to create a real type to replace the operators used, but before I spend time, I was wondering if there are any pros / cons to preserving the current implementation.

+5
source share
2 answers

Generally, if the data structure is some entity in your application domain model, it should get its own type; this makes the code more understandable and understandable. On the other hand, if you need it only List<List<string>>for intermediate data processing, there is no real benefit to creating a suitable one for this type.

, , , , " ". , (, - , - , , , ).

+3

, , () ( ). - ,

using pType1 = List<type2WhichType1InheritsFrom>;

(s) , - , , , .

+1

All Articles