473,395 Members | 1,401 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,395 software developers and data experts.

How to implement the following function/method?

What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.

Aug 11 '07 #1
6 1344

"ydbn" <yd**@discussions.microsoft.comwrote in message
news:D1**********************************@microsof t.com...
What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.

The question is what do you want to evaluate?
string YourFunction (string strParameter)
{
string result;

// Code for something to evaluate

return result;
}
Aug 11 '07 #2
the parameter will have some value like:

"100>10 && 100<1000 ? 1 : 0"
"'a' in ('a','b','c')"
etc.

"Joza" wrote:
>
"ydbn" <yd**@discussions.microsoft.comwrote in message
news:D1**********************************@microsof t.com...
What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.

The question is what do you want to evaluate?
string YourFunction (string strParameter)
{
string result;

// Code for something to evaluate

return result;
}
Aug 11 '07 #3
On Fri, 10 Aug 2007 22:38:00 -0700, ydbn
<yd**@discussions.microsoft.comwrote:
>What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.
I don't know if this is the best/easiest way, but it is a way.

The parameter string has to be a complete compilable program, or at
least something that can be turned into a complete program easily.

1 If needed turn the parameter string into a string containing a
complete program.
2 Save the complete program string to a file.
3 Invoke the C# compiler to compile the program file into an exe file.
4 Invoke the newly created exe file.
5 Retrieve and return the result.

rossum

Aug 11 '07 #4
"ydbn" <yd**@discussions.microsoft.comwrote in message
news:93**********************************@microsof t.com...
the parameter will have some value like:

"100>10 && 100<1000 ? 1 : 0"
"'a' in ('a','b','c')"
etc.
ok. but be more precisely. I'm little bit confused right now what do you really want? :D
Do you need algorithm for extracting some values from given parameter or something else?
Aug 11 '07 #5
rossum <ro******@coldmail.comwrote:
On Fri, 10 Aug 2007 22:38:00 -0700, ydbn
<yd**@discussions.microsoft.comwrote:
What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.
I don't know if this is the best/easiest way, but it is a way.

The parameter string has to be a complete compilable program, or at
least something that can be turned into a complete program easily.

1 If needed turn the parameter string into a string containing a
complete program.
2 Save the complete program string to a file.
3 Invoke the C# compiler to compile the program file into an exe file.
4 Invoke the newly created exe file.
5 Retrieve and return the result.
If you use CSharpCodeProvider, you don't need to write it to file or
convert it into an executable - just compile it from memory and into
memory. I'm doing that all the time at the moment, and it works well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 12 '07 #6
ydbn wrote:
What's the best easy way to have a function/method:

1. Has a string paramter, the value of string is C#/VB.Net express.
2. The function evaluate the express and return the value.
If you can live with JavaScript syntax, then JScript has a nice
eval function for doing this.

And a JScript class with a wrapper method can be called
from C#.

Arne
Aug 12 '07 #7

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

Similar topics

15
by: Prabu | last post by:
Hi, I'm new to python, so excuse me if i'm asking something dumb. Does python provide a mechanism to implement virtual functions? Can you please give a code snippet also...:) Thanx in advance...
14
by: Medi Montaseri | last post by:
Hi, I think my problem is indeed "how to implement something like java's final in C++" The long version.... I have an abstract base class which is inherited by several concrete classes. I...
26
by: Oplec | last post by:
Hi, I am learning standard C++ as a hobby. The C++ Programming Language : Special Edition has been the principal source for my information. I read the entirety of the book and concluded that I...
8
by: ATS | last post by:
HOWTO Implement LoadLibrary\GetProcAdrress\FreeLibrary in C# Please help, I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and be able to call functions that I use...
7
by: Don | last post by:
Can anyone give me an example of implementing ICloneable to give a class I created a "Clone" method so I can make copies of objects. I have no idea where to begin with this. Thanks. - Don
1
by: Pieter | last post by:
Hi, I have my own custom BindingList, that inherits from BindingList, and implements IComponent. I would like to implement a Find-method, that will allow me to search for a property of my...
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.