evaluating strings in C# 
Author Message
 evaluating strings in C#

In JavaScript, the eval method evaluates a string ex.
eval(document.form.checkbox[0].value);
Is there an equivalent function in C#?


Tue, 15 Feb 2005 23:01:27 GMT  
 evaluating strings in C#
MG,

    No, there is not.  The best you can do is compile the classes into an
assembly and then load the assembly.  However, this is not really the same,
as you would have to encapsulate the code in a class, and then execute the
method on that class.  At best, it would be a kludgy workaround.

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> In JavaScript, the eval method evaluates a string ex.
> eval(document.form.checkbox[0].value);
> Is there an equivalent function in c#?



Tue, 15 Feb 2005 22:55:34 GMT  
 evaluating strings in C#
Whoa. I was thinking that would be part of basic functionality from C#.
Could you please give me an example of your workaround?

Thanks Nicholas.



Quote:
> MG,

>     No, there is not.  The best you can do is compile the classes into an
> assembly and then load the assembly.  However, this is not really the
same,
> as you would have to encapsulate the code in a class, and then execute the
> method on that class.  At best, it would be a kludgy workaround.

>     Hope this helps.

> --
>                - Nicholas Paldino [.NET/C# MVP]



> > In JavaScript, the eval method evaluates a string ex.
> > eval(document.form.checkbox[0].value);
> > Is there an equivalent function in c#?



Tue, 15 Feb 2005 23:32:08 GMT  
 evaluating strings in C#
Scourge,

    Not really.  I mean, C# is a compiled language.  Javascript is an
interpreted script language.  If you have an interpreted language, then
everything is evaluated.  This is not the case with a compiled language.

    Doing this sort of thing is almost impossible, because you have to parse
the expression beforehand, use reflection to get all of the variables in the
expression, and then pass them to the other class that you are going to
compile (due to visibility of the members).

    It's just one big pain.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> Whoa. I was thinking that would be part of basic functionality from C#.
> Could you please give me an example of your workaround?

> Thanks Nicholas.


wrote

> > MG,

> >     No, there is not.  The best you can do is compile the classes into
an
> > assembly and then load the assembly.  However, this is not really the
> same,
> > as you would have to encapsulate the code in a class, and then execute
the
> > method on that class.  At best, it would be a kludgy workaround.

> >     Hope this helps.

> > --
> >                - Nicholas Paldino [.NET/C# MVP]



> > > In JavaScript, the eval method evaluates a string ex.
> > > eval(document.form.checkbox[0].value);
> > > Is there an equivalent function in c#?



Tue, 15 Feb 2005 23:34:38 GMT  
 evaluating strings in C#
Oh, and the JScript source...

public class EvalWrapper
{
   static function Eval(inval : String)
   {
      return eval(inval);
   }

Quote:
}

--
Robert Jeppesen
MindCom AB
http://www.mindcom.se/
Quote:

> You can use a wrapper class created in JScript.Net for this.
> I've attached a dll. In your project, add a reference to this dll AND Microsoft.JScript.
> Then in code, use this (you won't see intellisense with this, but it will compile):
> EvalWrapper.Eval("1+1")

> --
> Robert Jeppesen
> MindCom AB
> http://www.mindcom.se/


> > In JavaScript, the eval method evaluates a string ex.
> > eval(document.form.checkbox[0].value);
> > Is there an equivalent function in c#?



Wed, 16 Feb 2005 00:40:58 GMT  
 evaluating strings in C#
Excellent! Thank you :)


Quote:
> Oh, and the JScript source...

> public class EvalWrapper
> {
>    static function Eval(inval : String)
>    {
>       return eval(inval);
>    }
> }

> --
> Robert Jeppesen
> MindCom AB
> http://www.mindcom.se/




Quote:
> > You can use a wrapper class created in JScript.Net for this.
> > I've attached a dll. In your project, add a reference to this dll AND
Microsoft.JScript.
> > Then in code, use this (you won't see intellisense with this, but it
will compile):
> > EvalWrapper.Eval("1+1")

> > --
> > Robert Jeppesen
> > MindCom AB
> > http://www.mindcom.se/




- Show quoted text -

Quote:
> > > In JavaScript, the eval method evaluates a string ex.
> > > eval(document.form.checkbox[0].value);
> > > Is there an equivalent function in c#?



Wed, 16 Feb 2005 01:08:08 GMT  
 evaluating strings in C#
I was looking for an eval in C#, but I realized that it wasn't
script... so it kind of doesn't make sense.... unless IL has an eval
function.

chris

Quote:

> In JavaScript, the eval method evaluates a string ex.
> eval(document.form.checkbox[0].value);
> Is there an equivalent function in c#?



Wed, 16 Feb 2005 06:03:13 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How to evaluate a C# statement?

2. Evaluating functions using IDebugger Evaluate member.

3. Expresions Matematic Dimamic Evaluated in C# ?

4. Evaluate a string as a variable

5. newbie question on evaluating a string variable

6. evaluating strings??

7. Turning a string into a function and evaluate it

8. evaluate a string as a mathematical expression

9. Evaluating strings please help

10. How to mathematicaly evaluate string?

11. Function wanted to evaluate string

12. simple methode to evaluate a command string

 

 
Powered by phpBB® Forum Software