0

Possible Duplicate:
Is it possible to dynamically compile and execute C# code fragments?

Javascript being an interpreted language has the capability to evaluate expressions passed as strings as boolean expressions (for example) at runtime.

So, the boolean expression string

 string expression = "(125 >= 50 && 125 < 150) || (95 >= 70 && 95 < 100)"

can simply be passed to the eval function

result = eval (expression)

and the result will be a boolean. I want to do the same thing using C# with Mono for iOS. I looked up "equivalent of Javascript eval in C#" and all the results that showed up were using some form of on the fly compilation (some were using the Javascript eval function bundled into a DLL).

However, iOS does not allow on the fly compilation and requires all code to be precompiled. Given this situation, I want to know if there is an implementation of eval for C# that does not use on the fly compilation.

Note that I am only interested in boolean expressions like the above. Thanks.

Community
  • 1
  • 1
CodeBlue
  • 14,631
  • 33
  • 94
  • 132
  • Just curious: Why do you want this? – Cerbrus Dec 03 '12 at 14:55
  • 2
    Not sure iOS allows any of this. http://stackoverflow.com/questions/355062/is-there-a-string-math-evaluator-in-net – holmes Dec 03 '12 at 14:57
  • 2
    What makes you think that `eval` like behaviour will not be tantamount to "on the fly compilation", as far as Apple are concerned? – Oded Dec 03 '12 at 14:57
  • 3
    Even if it's possible, you almost surely *shouldn't* be doing this. The possible security vulnerabilities that you open yourself up to are significant, it results in highly difficult to maintain applications, and can be implemented in more practical manors without resorting to doing this. – Servy Dec 03 '12 at 14:58
  • @Cerbrus I'm working on an app where I am implementing a rules engine. – CodeBlue Dec 03 '12 at 15:00
  • Eval is **EVIL**. Really. Just don't do it. As a simplistic example, I could do things like supply a string for your rules engine that spams everyone in your iPhone's contacts list, and returns true on success. – Joel Coehoorn Dec 03 '12 at 15:15
  • What is this a duplicate of? The suggested duplicate is absolutely irrelevant. – CodeBlue Dec 03 '12 at 19:27
  • If using Xamarin.IOS you can use the additional mtouch flag --interpreter and be able to use Mono.CSharp.Evaluator. There are very few plausible uses for doing so though, namely for making a REPL environment for C# on IOS. If you are just building essentially expressions for evaluating conditions Linq Expressions is most likely better suited for this purpose though. – John Ernest Dec 08 '20 at 05:34

0 Answers0