Code Generators or T4 Templates, are they really evil?

前端 未结 15 1387
[愿得一人]
[愿得一人] 2021-01-31 12:19

I have heard people state that Code Generators and T4 templates should not be used. The logic behind that is that if you are generating code with a generator then there is a bet

15条回答
  •  后悔当初
    2021-01-31 13:16

    Maybe it is a bit harsh, but for me code generation smells.

    That code generation is used means that there are numerous underlying common principles which may be expressed in a "Don't repeat yourself" fashion. It may take a bit longer, but it is satisfying when you end up with classes that only contain the bits that really change, based on an infrastructure that contains the mechanics.

    As to Generics...no I don't have too many issues with it. The only thing that currently doesn't work is saying that

    List a = new List();
    List o = a;
    
    
    

    But even that will be possible in the next version of C#.

    提交回复
    热议问题