Search code examples
c#razorengine

Calling functions in razorengine


I am using http://antaris.github.io/RazorEngine/ to generate strings from a template and am having trouble calling functions within the template. The documentation on the site is a bit lacking with examples, but I am trying to call the double ToString function with a format. The format string is:

"The value of sensor @Model.Measurement.Sensor.Description is out of spec with a value of ((double)@Model.AdjustedValue).ToString(\"#.##\")"

The last part of the string I would like the output to be rounded to the nearest hundredth, but instead of I am getting the following string:

"The value of sensor Test_sensor_1 is out of spec with a value of ((double)78.14215625).ToString("#.##")"

Could someone point out the correct syntax for what I am trying to achieve.


Solution

  • Your @ is in the wrong place, I think:

    "The value of sensor @Model.Measurement.Sensor.Description is out of spec with a value of @(((double)Model.AdjustedValue).ToString(\"#.##\"))"