473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

eval equivalent

I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to
strong data typing, but thought I'd ask.

Thx!
Andrea
Nov 16 '05 #1
5 6367
Andrea,

There really isn't anything that will allow you to do this. C# is not
an interpreted language, like JavaScript is. Because of that, there is no
easy eval functionality. You could write the code out yourself, and create
an assembly dynamically, but you would have to use reflection to make the
calls, or have an interface that is defined elsewhere implemented on the
classes you create.

You are better off creating an interface/base class definition and then
having classes derive from that.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrea Williams" <an*******@hotmailIHATESPAM.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to
strong data typing, but thought I'd ask.

Thx!
Andrea

Nov 16 '05 #2
I suspected something like this... Thanks!

Andrea
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uO**************@TK2MSFTNGP15.phx.gbl...
Andrea,

There really isn't anything that will allow you to do this. C# is not
an interpreted language, like JavaScript is. Because of that, there is no
easy eval functionality. You could write the code out yourself, and create an assembly dynamically, but you would have to use reflection to make the
calls, or have an interface that is defined elsewhere implemented on the
classes you create.

You are better off creating an interface/base class definition and then having classes derive from that.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrea Williams" <an*******@hotmailIHATESPAM.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to strong data typing, but thought I'd ask.

Thx!
Andrea


Nov 16 '05 #3
No C# doesn't have it, but you can always build a managed assembly using
JScript.Net that executes a string passed to a function that executes the
'eval' function.

Willy.

"Andrea Williams" <an*******@hotmailIHATESPAM.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to
strong data typing, but thought I'd ask.

Thx!
Andrea

Nov 16 '05 #4
You could try this:
http://www.codeproject.com/csharp/runtime_eval.asp

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Andrea Williams" <an*******@hotmailIHATESPAM.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to
strong data typing, but thought I'd ask.

Thx!
Andrea

Nov 16 '05 #5
One more sample here:
http://odetocode.com/Articles/80.aspx

--
Scott
http://www.OdeToCode.com

On Tue, 7 Sep 2004 13:46:12 -0700, "Andrea Williams"
<an*******@hotmailIHATESPAM.com> wrote:
I'm looking for an equivalent to the JavaScript function 'eval'. Anyone
know one that will work in C#? I'm guessing that it doesn't exist due to
strong data typing, but thought I'd ask.

Thx!
Andrea


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: robcarlton | last post by:
hi everybody I've written this function to make a list of all of an objects attributes and methods (not for any reason, I'm just learning) def list_members(obj) l = dir(obj) return map(lambda...
9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
1
by: Mad Scientist Jr | last post by:
Is there a native .NET equivalent of the Microsoft Script Control, particularly the Eval method? See here: http://www.devx.com/vb2themax/Tip/18773 It works great - it even compares string...
11
by: Dark Cowherd | last post by:
http://www.ucalc.com/mathparser/index.html There is a great library called UCALC which allows you to set up an expression and evaluate it for e.g. you an define an expression by calling a...
3
by: Eric Caron | last post by:
Hi everybody, Is there an operator that would do the same job as the eval operator in javascript? I have a bunch of checkboxes ranging from 1 to 22 and would like to evaluate their values using...
5
by: Ido.Yehieli | last post by:
Hi all, I'm new to c# and .net and I have a few questions I did not manage to find an answer to: 1. what is the equivalent to the "exec" command in python/lisp? meaning: a string is given as...
8
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
12
by: Bill Mill | last post by:
Hello all, I want to have a user able to eval code in a text box. However, if he accidentally types "while(1) { i=0; }" and hits "run", I also want him to be able to hit a stop button such that...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.