Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# Eval() or compile on fly with object

Status
Not open for further replies.

andysk

IS-IT--Management
Sep 15, 2000
53
ID
Hi,

I have tried using CodeDomProvider to compile the code on fly and get the value returned, like :
string sEval = "1+1", will always return 2.

However when i try to use the same concept on object like example below, i got an error :

I have a webform with 3 textbox on it, named Label1, Label2, Label3.

Label1.Text = "my first name"
Label2.Text = " my family name"

string sEval = "Label3.Text = Label1.Text + Label2.Text"
now i want to run sEval that will fill Label3.Text = "my first name, my family name".

how to achieve that? please help.

Thanks in advance,
Andy
 
why would you code C# this way? you don't need access to the CodeDomProvider, especially in the UI.

if you want to format text use string.Format
Code:
var sirname = "Meckley";
var firstname = "Jason";
var formatted = string.Format("{0}, {1}", sirname, firstname);

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Hi JMeckley,

this is just an example, i just want to know how to make it works.
I have a program (aspx) that will receive a parameter, based on the parameter, this program will get all required data from server. within the data, it contains a lot of object (that should be created) along with it properties (that should be set). for creating object on fly, i found no issue, however, when came to setting its properties, i don't know how to make it works. Can be say i am a lazy programmer, that always find a way to make the program shorter and easier to be maintained.
Anyway, please enlighten me, how to make it works.
thanks.
 
what you say all makes sense, it's the cornerstone of every application. how that problem is solved can vary for each application, but the principles are the same.

it's the goal (or should be anyway) of every developer to create maintainable code that is simple to understand, even when solving complex problems. How one defines simple can vary, but for the most part this is what we strive for.

Maybe, I'm misinterpreting what you have written, but it sounds like you want to build an application without any knowledge of C#, webforms, asp.net or programming with static OOP languages. If this is the case, then you need to research how these various concepts, languages and frameworks operate, before you begin coding.

If this is not the case then you need to narrow the scope of problem. Solve what you can and then ask for assistance with the unknown.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Hi Mickey,

Partially your guess was right. i have only some knowledge of C#.
Aside from that, of course i can just add a lot of webforms that mimic like each webform should be, create objects and set the properties in design time. it's much more easier, but that's not the way i want it. In some articles, they said that can be achieve through JScript, (like this example however, most of the examples are not related to getting values from object or setting values of object dynamically.

Anyway, thanks mickey.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top