Search code examples
c#.netvb.netintersystems-cacheindirection

Can you perform code indirection in .NET?


I remember with InterSystems Cache code, you can use indirection to take a string and turn that into real executable code by preceding the string variable with "@". Can this be done in C#.NET or VB.NET code? So I'd like to have a method that would take an arguments array of strings (with one or multiple lines of code), and run that code, assuming it doesn't throw an exception of course. Where am I going with this? I'm trying to write a compiler within .NET code.

SET x="set a=3" XECUTE x   ; sets the public variable a to 3

OR

SET x="tag1" d @x  ; do/call the public subroutine tag1

OR 

Set Y = "B",@Y = 6  ; sets public variable B = 6

Solution

  • I assume that you want to compile during runtime.
    System.CodeDom and System.CodeDom.Complier namespaces contain interfaces that are relevant to runtime compilation.
    For your own language you need to implement your derived class from a derived class of CodeDomProvider.