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? 5 7482
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
On 19 Jan 2006 06:08:55 -0800, "Larry Lard" <la*******@hotm ail.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_o f_string1 >=
integer_value_o f_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?
Hi,
"Digital Fart" <pr*********@an gelfire.com> wrote in message
news:0t******** *************** *********@4ax.c om... 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
Digital Fart wrote: On 19 Jan 2006 06:08:55 -0800, "Larry Lard" <la*******@hotm ail.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_o f_string1 >= integer_value_o f_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(num ber1);
int n2 = Int32.Parse(num ber2);
switch(op)
{
case "==":
return (n1 == n2);
case "!=":
return (n1 != n2);
//etc
}
}
--
Larry Lard
Replies to group please This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 24-28, 200)
Organization committee:
Roel Wuyts (primary contact - roel.wuyts@ulb.ac.be), Gilad Bracha,
Wolfgang De Meuter, Stéphane Ducasse and Oscar Nierstrasz.
|
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 with the application.
When a new component is shipped, the application 'picks up' that
component and drops it in to the interface (in this case a GUI button
as well as an associated class with that gui buttion). The application
then uses the...
|
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 below...
--
|
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 stop by in here.
Crystal's knowledgebase has made available a bunch of examples for both
ASP.Net and VB.Net applications for download and review (I added the links
at the end of this post). One of the examples is how to pass in a parameter
to...
|
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 desirable.
I have a web service that, based on an input parameter, dynamically loads A,
B or C library. I also understand that an separate AppDomain is needed to
explicitly unload the Assembly. No other apps will use these assemblies.
Do I need...
| |
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 execute this function dynamically.
So I have a function list in database written as a string. I am now looking
for function or mechanism which will execute function dynamically.
I am here Giving a example.
|
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 SQL-Select-string and a type as
parameters. It will then return a collection of objects of
the specified type. (I have ~30 object types that will be
fetched in exactly the same way from one table each).
Dynamic parsing works fine using the Reflection...
|
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
|
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 or another (could also be 3) different web servers to
use these Web Services. The Web Services are identical on all the machines.
I tried just changing the URL of the Web Services and cannot make it work.
I then decided to create 2 identical web...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |