frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
537 stars 132 forks source link

how do you debug a tst file? #121

Open gregveres opened 8 years ago

gregveres commented 8 years ago

HI @frhagn

I have the following in .tst file and I would like to be able to console.log stuff so I can see what I am working with. Is that possible?

${
    string KnockoutType(Property p) {
        if (p.Type.IsEnumerable) {
console.log($p.Type);
            return p.Type.Name.TrimEnd('[',']');
        }

        return p.Type;
    }

thanks.

I am trying to use a 2 dimensional array in C# and converting that to a knockout observable array, but what appears to be happening is that Property.Type only has a single [] but $Type within a property section seems to have the proper [][]. So I would like to dump out these values to see what I am working with.

Thanks Greg

gregveres commented 8 years ago

No rush on answering. I would like to know how to best debug .tst files. But for this issue, I have realized how I can get away from a 2 dimensional array. I think moving away from the 2-D array makes it easier to work with the classes anyway.

Thanks Greg

banyard commented 8 years ago

There may be a better solution but in terms of general debugging with Typewritter I usually append information to a string then output this within a comment in my template. Something like:

${
     static string debugInfo = "";
     string PrintDebugInfo(File f){
          return debugInfo;        
     }

     string KnockoutType(Property p) {
          if (p.Type.IsEnumerable) {
               debugInfo = p.Type.ToString();
               return p.Type.Name.TrimEnd('[',']');
          }
          return p.Type;
     }
}
/* 
     Debug Info:
     $PrintDebugInfo
/*
gregveres commented 7 years ago

ah that's a good idea. I will keep that in mind the next time I need to debug. Thanks.

frhagn commented 7 years ago

Nice one @banyard!

sonuautade commented 7 years ago

It reminded me of days when we used to write printf statement in C code to debug it

aluanhaddad commented 7 years ago

@sonuautade Yeah, but it is better than nothing.

@frhagn Would it be possible to have a way to print message via System.Diagonistics.Debug.WriteLine or, better yet, to have a flexible logging mechanism such as

${
    using Typewriter.Extensions.Types;
    using static System.Diagonistics.Debug;

    Template(Settings settings)
    {
        settings.UseLog(WriteLine);
    }
}

I'd be happy to create a PR for that if it sounds reasonable/feasible

JNotelddim commented 5 years ago

@aluanhaddad Any progress on that PR?

Prinsn commented 2 years ago

Or anyone.

gregveres commented 2 years ago

I have successfully migrated to NTypewriter. I am still using Typewriter for and old part of my code base that is being migrated to a new UI framework and as I migrate the code base, I migrate from Typewriter to NTypewriter.

In my opinion, the only thing issing from NTypewriter is the automatic running of the template renderer when a file gets saved. But it can definitely handle everything else that I got from Typewriter.