Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Philippe Arteau
@h3xstream
It there a way to use this parser to parse template without executing them ..
I am looking for a way visit only the blocks of the template.
Matthias Dittrich
@matthid
@h3xstream No, currently there is no easy way. The generated code depends on RazorEngine so it might not be as useful as you might assume... What do you mean by "blocks"?
Philippe Arteau
@h3xstream
@matthid I meant nodes of the template. HTML, code and possibly code instructions.
(But are not exposed publicly)
Matthias Dittrich
@matthid
You might want to use Razor directly (without RazorEngine), we might provide API in the future to get the source code (and transform it with Roslyn), but never such a visitor API... The reason is quite simple: First we at RazorEngine try to abstract away the concrete Razor version for you. And secondly Razor 4 is changing dramatically and maintaining such an API is an additional headache...
You can however look into the RazorEngine source code to get an idea how to use the Razor classes (see DirectCompilerServiceBase for example)
Richard Bogle
@Boggin
I've been trying to implement the MvcTemplateBase<> as shown in Issues #26 and #29 but I get a null for the HttpContext.Current and I can't figure out why. I'm using the fluent config to set the BaseTemplateType = typeof(MvcTemplateBase<>). Is this going to work or have I got lost! RazorEngine v.3.7.2
Richard Bogle
@Boggin
Hang on. WebAPI ...
Nikola Sivkov
@aviatrix
hey @matthid , are you around ?
Matthias Dittrich
@matthid
Hey, yes whats up?
Nikola Sivkov
@aviatrix
Can you tell me if you recall, in versions prior to 3.5 did RE store the compiled templates on disk or in memory ?
Matthias Dittrich
@matthid
In memory (which has some downsides), but you can still to it with DisableTempFileLocking (so I basically changed the default)
Nikola Sivkov
@aviatrix
i have a theory on why using linq methods on dynamic properties blows up now and it didn't before
ah, i see
Matthias Dittrich
@matthid
why would it matter on linq methods?
Nikola Sivkov
@aviatrix
something to do with parts of anon/dynamic objects being internal
and since they are stored outside of the memory now, they are different assembly
and executing assembly not being able to see the internal stuff and blowing up
Matthias Dittrich
@matthid
First if you use dynamic we have some RazorEngine internal trickery in place to wrap the dynamic/anon object so that you can access internal stuff in the template
Matthias Dittrich
@matthid

Second its not a RazorEngine limitation as the following code shows:


    using System;
    using System.Linq;

    public class Test
    {
        public static dynamic TestMethod()
        {
            var a = new[] { "first", "second", "self" };
            var ext = a.First();
            dynamic c = new[] {"first", "second", "self"};
            return c.First();
        }

        public static void Main(string[] args)
        {
            string ret = TestMethod();
        }
    }

try to compile an run it

Nikola Sivkov
@aviatrix
yeah, it blows up
sorry if i'm being annoying, i'm just trying to understand what has changed, and why my code blows up now
Matthias Dittrich
@matthid
Sorry if my answers felt rude, I just tried to get them on point. By the way a lot of things changed in 3.5 but I tried my best to make everything as much backwards compatible as possible... This especially this place (dynamic/anonymous classes) is a minefield...
Nikola Sivkov
@aviatrix
It wasn't rude :)
Matthias Dittrich
@matthid
It might have worked in the past because we used to try to "guess" the type with a combination of generic parameter and "model.GetType()" which often worked as expected, often worked (but not as one would imagine) and sometimes failed in some corner cases.
But from your description I would say it was a bug if it ever worked (without knowing the exact template and RazorEngine call you used)
Nikola Sivkov
@aviatrix
in my case i tried to construct a dynamic object form a dictionary
var  tpl = Razor.GetTemplate(templateHtml, new {}, pageCacheKey);
var viewbag = new DynamicViewBag();              
var ctx = new ExecuteContext(viewbag);
var result = tpl.Run(ctx);
Matthias Dittrich
@matthid
Is there something blocking you from updating to the latest API (Documentation: https://antaris.github.io/RazorEngine/index.html)
Nikola Sivkov
@aviatrix
i was't using the viewbag anyway
no, i've updated fully
but found that couple of client templates broke after the update
(writing my own CMS for clients, and whatnot )
Matthias Dittrich
@matthid
a concrete sample would be nice: the template, the old RazorEngine call and the new call
Nikola Sivkov
@aviatrix
i will try to get that to you
@matthid Good night, and thanks for the help & your time !
Matthias Dittrich
@matthid
Good night, you are welcome :)
Nikola Sivkov
@aviatrix
@matthid ping
Matthias Dittrich
@matthid
pong
Nikola Sivkov
@aviatrix
how's it going :)
Matthias Dittrich
@matthid
fine and you?
Nikola Sivkov
@aviatrix
same, same
today i'm trying another approach to see how it goes, in regards to "dynamics"
Matthias Dittrich
@matthid
good luck :)
Nikola Sivkov
@aviatrix
thank you!
i'm generating a class at runtime with reflection
Matthias Dittrich
@matthid
puh, why do you even need that?