Home

Vici Core - Expression Parser - Basics

Documentation is in the works, but here are simple examples of the expression parser and template engine:

Expression Parser

IParserContext context = new CSharpContext();

context.AddType("Math", typeof(Math));
context.Set("SomeString", "Hi there!");
context.Set("SomeNumber", 20);
context.AddFunction("fmt",  typeof(String), "Format");

CSharpParser parser = new CSharpParser();

string stringValue = parser.Evaluate<string>("fmt(\"I said: {0}\", SomeString)", context);  
// returns "I said: Hi there!"

int intValue = parser.Evaluate<int>("Math.Max(10, SomeNumber)" , context); 
// returns 20

double doubleValue = parser.Evaluate<double>("SomeNumber * 2.0", context); 
// returns 40.0