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

creating a dynamic if statement via reflection

I have 3 strings containing "10" , "20", ">="

would it be possible via reflection to generate a dynamic if statement
that return true or false and testing it like this

if ( 10 >= 20 )

so a string becomes a test of 2 integers

and how would i code this?
Jan 19 '06 #1
5 7422

Digital Fart wrote:
I have 3 strings containing "10" , "20", ">="

would it be possible via reflection to generate a dynamic if statement
that return true or false and testing it like this

if ( 10 >= 20 )

so a string becomes a test of 2 integers

and how would i code this?


Well, the easy answer is that 10 isn't greater than or equal to 20, so
you don't need that if statement :)

But seriously, we need to know what the actual inputs are. Do you have:

- a string containing the representation of an integer, another such,
and the string ">="
- a string containing the representation of an integer, another such,
and a string containing a C# comparison operator
- a string containing the representation of some kind of number,
another such, and a string containing a C# comparison operator
- three arbitrary strings that when concatenated yield an expression
with a boolean value
- three arbitrary strings that when concatenated might yield an
expression with a boolean value

or something else?

--
Larry Lard
Replies to group please

Jan 19 '06 #2
On 19 Jan 2006 06:08:55 -0800, "Larry Lard" <la*******@hotmail.com>
wrote:

3 strings that contain a value that represent an integer
( i read them from a flatfile )
the operator is something the user can enter as a string

so
string1 = "10"
string2 = "20"
operatorstring = ">="

now i need to know if integer_value_of_string1 >=
integer_value_of_string2

does this make more sence?


Digital Fart wrote:
I have 3 strings containing "10" , "20", ">="

would it be possible via reflection to generate a dynamic if statement
that return true or false and testing it like this

if ( 10 >= 20 )

so a string becomes a test of 2 integers

and how would i code this?


Well, the easy answer is that 10 isn't greater than or equal to 20, so
you don't need that if statement :)

But seriously, we need to know what the actual inputs are. Do you have:

- a string containing the representation of an integer, another such,
and the string ">="
- a string containing the representation of an integer, another such,
and a string containing a C# comparison operator
- a string containing the representation of some kind of number,
another such, and a string containing a C# comparison operator
- three arbitrary strings that when concatenated yield an expression
with a boolean value
- three arbitrary strings that when concatenated might yield an
expression with a boolean value

or something else?


Jan 19 '06 #3
bb
what about using an eval class (similar to the javascript one)

an example of which is here http://www.osix.net/modules/article/?id=761

Jan 19 '06 #4
Hi,

"Digital Fart" <pr*********@angelfire.com> wrote in message
news:0t********************************@4ax.com...
I have 3 strings containing "10" , "20", ">="

would it be possible via reflection to generate a dynamic if statement
that return true or false and testing it like this

if ( 10 >= 20 )

so a string becomes a test of 2 integers

and how would i code this?


you could use some eval class, I think I saw a link a time ago here, look in
the archives.

otherwise if you know that you have two string that can be converted to
integer you could do a Convert.ToInt32 with them, using the third string (
the operator) as the expression of a switch clause, after all the operators
are a finite number.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 19 '06 #5

Digital Fart wrote:
On 19 Jan 2006 06:08:55 -0800, "Larry Lard" <la*******@hotmail.com>
wrote:

3 strings that contain a value that represent an integer
( i read them from a flatfile )
the operator is something the user can enter as a string

so
string1 = "10"
string2 = "20"
operatorstring = ">="

now i need to know if integer_value_of_string1 >=
integer_value_of_string2

does this make more sence?


Sure does!

Use Int32.Parse to convert the strings to ints; then just switch on the
operator and perform the appropriate comparison:

// validation? error handling? not in this sample!
bool Compare(string number1, string number2, string op)
{
int n1 = Int32.Parse(number1);
int n2 = Int32.Parse(number2);

switch(op)
{
case "==":
return (n1 == n2);
case "!=":
return (n1 != n2);
//etc
}
}

--
Larry Lard
Replies to group please

Jan 19 '06 #6

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

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
3
by: jonathan | last post by:
hey all, I'd like to implement an application that is truly dynamic: the components are not only just known at runtime, but also the components are unknown at runtime: ie: some don't even ship...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
4
by: Andrew | last post by:
Hey all, Been working with the Crystal Report Viewer, and have run into a situation I am hoping someone can help me get past. This may be more of a CR question, but hoping for some CR gurus to...
4
by: BrianS | last post by:
What is the best strategy for dynamic loading private assemblies in asp.net? I understand, and have confirmed, that any dll placed in the app's /bin dir will get loaded on startup. This is not...
9
by: Kishor | last post by:
Hi all, I am Using VB.Net for developing my application. I am now needed help. In this project I have to execute some function, but I cannot call them directly using function name, I wanted to...
3
by: Jakob Lithner | last post by:
I have searched the news groups on similar subjects, but haven't found anything adequate for my need .... To save much duplication of code I would like to create a baseclass that takes a...
2
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.