Razorlight: How can I escape out of parsing

Created on 7 Feb 2017  路  7Comments  路  Source: toddams/RazorLight

I am trying to do this:

include "@{Model.ClassName}.h"

to produce

include "classname.h"

but I get string does not contain a definition for h!

How do I escape out of parsing before the .

question

All 7 comments

You can declare a variable somewhere at the top and then use it, for example

@{
string s = string.Format("{0}.h", Model.ClassName);
}

Thanks for quick reply.

Any chance of add support for something like this:
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

Mixing code and plain text (alternate)

@if (foo) {
  @:Plain Text is @bar
}

so @: switches back to plain text.

I think @: should work as well, as RazorLight uses Microsoft's Razor engine under the hoods.
Give it a try and let me know if it works (can't test it myself at the moment)

#include "@Model.ClassName@:.h"

didn't work

Will use your workaround for now, but would be nice to have @: working, its probably something I'm doing wrong.

@danwalmsley hey man, please don't use my handle to document your code, danke

@bar hehe interesting what happened there!

Was this page helpful?
0 / 5 - 0 ratings