Archived

This topic is now archived and is closed to further replies.

Has anyone found a string evaluator in the .NET base classes?

This topic is 5781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I am getting pretty deep into C# and .NET now and was looking for a function or class of some kind in the Base Classes that accepts a string and returns a numeric value from that string. For example, lets say the function is called "Eval" int result = SomeClass.Eval("5*(10)^2"); I know this must exist, but I can''t seem to find it in the documentation. The only version of this I can find was on MSDN and is VBA, which is no help to me. If anyone knows of one that is built into the .NET Base Classes please let me know, otherwise I have to code it and it probably won''t be as good :-) -SniperBoB-

Share this post


Link to post
Share on other sites
I''m pretty sure there isnt anything like that in the BCL - I have seen this come up in the C# newsgroup a couple of times. JScript.NET supports it though, so you could always write that part there and just reference the assembly in your C# project.
One other way you could do something like this by generating an assembly dynamically through the System.Reflection.Emit namespace. However, lLooking at the docs this seems like a pretty involved job and might be overkill for what you are trying to do.

(Yay - finally a .NET question that isn''t "Is C# good for games?")

The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)

Share this post


Link to post
Share on other sites
Just seconds after I posted this I thought to myself: "Wait! Can''t you dynamicly create IL code at run-time using something related to reflection!?" Ok so that''s not exactly what I thought, but it was close. Thanks for pointing me towards the Emit function... I think it may be helpful.

I wonder... would it be possible to use C# as a scripting language in a game?? Seems very possible to me! Maybe I''ll get right to working on that.

Forget what everyone else says: I''m on the DX9 beta team... the second I get that SDK I am going to be coding games in C# almost exlusively, I''m loving it.

Share this post


Link to post
Share on other sites
Looky here!

System.Reflection.Emit
Contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk. The primary clients of these classes are script engines and compilers.

Script Engines you say?? Hmmm, I''m interested... please tell me more!.... Surely, unfortunatly Microsoft has made the documents as unintellegable to read as possible... luckly this time they are well organized.

Share this post


Link to post
Share on other sites
I havent really used System.Reflection.Emit myself, but I know that mcs, the Mono C# compiler, uses these classes to generate the assemblies. So making a scripting engine based on this functionality should definitely be possible.

Share this post


Link to post
Share on other sites