Build if then statements at run time?
My product owner has asked me to make some comparision logic configurable so the process engineers can change things with开发者_如何学JAVAout making code changes. Currently the code is a SELECT CASE
statement with various IF THEN
statements that are fairly standard. The problem I can't seem to find a way around is that he wants through configuration to AND/OR
a variable number of comparisons in the IF THEN
statements. His idea is the that the configuration would work like a limited query builder for the process engineers. The only solution I've come up with is to build a function in a string and use the VBCodeProvider to compile it at runtime. Is there a better way to approach this?
One way to do it is just store the booleans in your configuration file, load them up at run time, and use them in your code like any other boolean.
A better way would be to have the configuration as close to his problem domain as possible, then code up the proper booleans from those to use in your code.
You could use expressions to accomplish this. With this you would be able to build up an IfExpression and build up its conditions. You would be able to compile this and run it all at runtime.
精彩评论