Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Evaluating string as if were code
Message
De
29/09/2004 07:50:31
 
 
À
28/09/2004 09:33:08
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00946586
Message ID:
00947114
Vues:
15
Bonnie,

Thanks for the link, as far as I can see Reflection is not the only way to get this done. I found some interresting code to play with from the article, however when trying to rewrite/adapt the code from C# to my VB project, I obvoiusly stumbled somewhere because the compiler just won't do the magic. When calling ICodeCompiler.CompileAssemblyFromSource I get an error saying:

Could not find file "C:\DOCUME~1\ASPNET\LOCALS~1\Temp\ylev4xcq.dll
(Different .dll file for each time)

Here is the code
Dim oCompProv As New VBCodeProvider
Dim oComp As ICodeCompiler = oCompProv.CreateCompiler()
Dim oCompParams As CompilerParameters = New CompilerParameters
oCompParams.ReferencedAssemblies.Add("System.dll")
oCompParams.ReferencedAssemblies.Add("[some more stuff].dll")
oCompParams.GenerateInMemory = True
Dim oCompRes As CompilerResults = oComp.CompileAssemblyFromSource(oCompParams, strCode)
Is this because I'm not referencing all needed DLLs or am I off target somewhere else?

Thanks a lot

>Danijel,
>
>Reflection *is* the way to do this, but go ahead and read Rick's article :
>(http://www.west-wind.com/presentations/DynamicCode/DynamicCode.htm)
>It's been awhile since I read it, but I'm sure that he has some nifty little trick to make it easy. In fact, here's a quote from the beginning of the article:
>
>"In this article, Rick takes a look what it takes to execute code dynamically with the .Net framework and introduces a class that simplifies the tasks by wrapping the details of the process in an easy to use interface that only requires a few lines of code."
>
>~~Bonnie
>
>
>>>You know in JSCript, there is an eval() function allowing you to execute a string as code. Is there any way of doing this in VB.NET?`
>>>
>>>Thanks
>>
>>By the way, I am aware of System.Reflection, but then I need to create separate assembly for each time I want to reference something. I would preffer if it were possible to keep the code in one place and reference function/sub/class within the same project.
Danijel
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform