Code Generators or T4 Templates, are they really evil?

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

    quote: I have not really found effective ways to build templates that can say for instance instantiate themselves. In otherwords I can never do :

    return new T();

    public abstract class MehBase
        where TSelf : MehBase, new()
    {
        public static TSelf CreateOne()
        {
            return new TSelf();
        }
    }
    
    public class Meh : MehBase, TParam1, TParam2>
    {
        public void Proof()
        {
            Meh instanceOfSelf1 = Meh.CreateOne();
            Meh instanceOfSelf2 = Meh.CreateOne();
        }
    } 
    

提交回复
热议问题