I'm trying to use the Expression tree and Lamdba Expression objects in .Net 3.5 to allow me to dynamically calculate boolean expression entered by a user.
So far a user can create an expression tree consisting of BinarayExpressions
that AND and OR values expressed as ParameterExpressions
. I was then planning on creating a LambdaExpression
based on that tree so that I could compile the expression into a delegate which I could then call. The issue I'm having is that I don't know how many input parameters the user will need so when I come to compile the expression into a delegate I don't know the method what the method signature should be until runtime.
So far I've come up with two possible solutions.
- Create a whole bunch of delegates
like the
Func<bool, bool, bool...>
ones which can take as many parameters as I think a user might possibly need. This doesn't feel like the most elegant solution but I think it would work, until someone wants to use one more parameter than I've catered for. - Pass in an array of values and somehow assign them to my parameters using the array indexer. I've thought about this but can't work out how it work.
NB: It needs to be quick so no boxing or anything like that.