# Saturday, March 01, 2008

In two of my open source projects (CoolStorage.NET and ProMesh.NET), I have to parse expressions from a string at runtime. Both products include a simple parser that supports most of the .NET expression syntax, but it is still too restricted compared to real C# expressions.

So I decided to create a separate C# open source project that allows you to include C# 2.0 expression parsing in your application.

The features of this library:

  • Light-weight (less than 60KB) with no dependencies
  • Late-bound context
  • Full C# 2.0 syntax
  • All .NET 2.0 types supported, including nullables
  • Support for calling any .NET method and creating any .NET object (provided you allow it)

The late-bound aspect is quite important. The expression parser can be called with a context object that contains all the variables and classes you want to expose to the expression. It is obvious that the expression parser doesn't know about the types of the objects you supplied, so when evaluating the expression, LazyParser.NET will use the same logic as the C# 2.0 compiler to determine what overloaded method to call, or what type of value to return from an expression, based on the runtime types in the context.

The project is almost ready to published as version 0.9. I still need to add some stuff like indexing operators, type casting and conditional operators, but other than that is working great.

The first version will be published on CodePlex sometime next week.

UPDATE: LazyParser.NET 0.9.1 has been published on CodePlex

kick it on DotNetKicks.com
Saturday, March 01, 2008 9:56:26 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [3] -

Tracked by:
"Link Listing - March 2, 2008" (Christopher Steen) [Trackback]
"Link Listing - March 2, 2008" (Christopher Steen) [Trackback]
Saturday, March 01, 2008 11:02:29 PM (W. Europe Standard Time, UTC+01:00)
I'm working in something similar right now, does your code support static classes?
Sunday, March 02, 2008 10:38:51 AM (W. Europe Standard Time, UTC+01:00)
Yes it does. It supports every C# 2.0 construct, except generics.
Monday, March 03, 2008 7:42:39 AM (W. Europe Standard Time, UTC+01:00)
cool, looking at it right now and testing on the scenarios I had to see if it works they I needed this for
Comments are closed.