How much flexibility do you need? if you just need to set the value from a
string use:-
string val = "2"; //perhaps this comes from a data file etc
int i = 0;
i = Integer.Parse(val);
Console.Writeline ("La valeur de i est: " + i);
If you have a finite number of operators you could write code in a switch
block so depending on the contents of your string e.g. "+=", "=", "-=". If
you also need to be able to specify which value you are modifying at runtime
you can do this too using reflection. use GetType on your object, and call
GetField with the parsed name, then SetValue. You will need to wrap in a try
catch block in case you specify a field name "x" which doesn't exist.
Peter
--
Peter Foot
Windows Embedded MVP
www.inthehand.com |
www.opennetcf.org
"Freddyboy" <(E-Mail Removed)> wrote in message
news

DE6FAFA-C670-4A31-9348-(E-Mail Removed)...
> Hi,
>
> I'd like to use System.Runtime.CompilerServices with the Compact framework
> because I want to execute code which is in a string like that :
>
> int i = 0;
> string action = "i = 2;";
> ????.Execute(action);
> Console.Writeline ("La valeur de i est: " + i);
>
> In the compact framwork, System.Runtime.CompilerServices is not supported.
>
> Somebody knows a solution ?
>
> Thanks.
>
> Best Regards.