Project DescriptionLazyParser.NET is a light-weight late-bound expression parser compatible with C# 2.0 expression syntax. It allows you to incorporate user-supplied mathematical expressions or any C# expression in your application which can be dynamically evaluated at runtime, using late binding. Any .NET class and/or method can be used in expressions, provided you allow access to them in an application-provided "context". This library is perfect for CMS systems, blog engines, ORM tools, etc. Features
- Evaluate any C# 2.0 expression at runtime
- Fully C# 2.0 spec compliant (operator precedence, nullable lifting, type promotion, ...)
- Late bound (objects can be passed at runtime, types are evaluated when the expression is evaluated)
- Function calls: support for member methods, static methods and delegates,
- Support for static fields, properties and classes
- Possibility to intercept field or property access at runtime
Examples of use
ParserContext context = new ParserContext();
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
|