none
How to run CodeDom code in the same context? RRS feed

  • Question

  • Hi,

    How to try to run a VB or C# code using CodeDom, by using the same context as the original application that is running it? I mean, the running code must be able to access all the variables and members of the parent application in which it is being run.

    For EX:

    Dim a as Integer
    a = 25
    Eval(" Msgbox ("" Hi the value is : "" + cstr(a)")

    This code must display the value of a as 25. And Eval is the equivalent function wherein codeprovider is used to generate the assembly. So is there anyway to run the code within the same assembly??


    Cheers
    Xinxua

    Fear is the end. End is the fear.
    Tuesday, July 15, 2008 9:56 AM

All replies

  • There's no easy, built in way to do that. You probably have to package up the variables you want to share with the compiled code and pass it in yourself (in a Dictionary for example). Keep in mind that variable name resolution is done at compile time, before the assembly is loaded into your app domain.
    Mattias, C# MVP
    Wednesday, August 13, 2008 8:25 AM
    Moderator
  • If Eval() is a function you declared in your CodeDom generate assembly, you can't get your main app compiled.  There is no Eval() function yet, not until your app runs.  You solve that by using interfaces and Assembly.CreateInstance().
    Hans Passant.
    Friday, August 15, 2008 10:29 AM
    Moderator