Code Generators or T4 Templates, are they really evil?

前端 未结 15 1596
[愿得一人]
[愿得一人] 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:14

    You can do new T(); if you do this

    public class Meh
      where T : new()
    {
      public static T CreateOne()
      {
        return new T();
      }
    }
    

    As for code-generators. I use one every day without any problems. I'm using one right now in fact :-)

    Generics solve one problem, code-generators solve another. For example, creating a business model using a UML editor and then generating your classes with persistence code as I do all of the time using this tool couldn't be achieved with generics, because each persistent class is completely different.

    As for a good source on generics. The best has got to be Jon Skeet's book of course! :-)

提交回复
热议问题