tags:

views:

68

answers:

2

I have some values in a configuration file (XML file) with some values like this:

 <IncreamentInSeconds>24*60*60</IncreamentInSeconds>
 ...

I could put 86400 value there, but it is more descriptive as a calculation expression. This is just a simple example. There are some other expressions as well, but they are all in a kind of calculation expressions.

I am not sure if there is any way to parse the expression and to get the result value of it in C#. I thought about Excel component that may be helpful, but I think that might cause performance issue (to load excel worksheet with cell?). Any other way to get the result?

By the way I saw some XCode examples to get expression result by using shell command to evaluate the result (the shell even be able to take variable definitions). Not sure if there is any shell command in Windows that could be used so that I may execute the shell command to get result?

A: 

I think I got the answer. I found that CodeDOM cab be used to get result from a calculation expression.

And here is an article with examples.

David.Chu.ca
It looks very powerful, however, very complicated. Any simple way?
David.Chu.ca
another similar example at: http://forums.techarena.in/software-development/1109842.htm
David.Chu.ca
+1  A: 

Probably the most simple way to do this is using Microsoft.JScript http://riteshk.blogspot.com/2007/05/how-to-calculate-value-with-regular.html

If you wanted to do this without using the javascript library you could always use Reverse Polish notation: http://en.wikipedia.org/wiki/Reverse_Polish_notation

Link to convert infix to RPN: http://montcs.bloomu.edu/~bobmon/Information/RPN/infix2rpn.shtml

Also here is a link to an RPN expression parser: http://www.codeproject.com/KB/cs/rpn_expressionparser.aspx

Justin