new to codedom

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a problem that I think codedom will solve, but it looks like a real
mess to me, and I don't know where to start. I'm using .NET 2003 FW 1.1 VB.

I have a few selection criteria, and each is easily implemented in 5 to 10
VB statements resulting in a boolean output (indicating selected or not
selected). The user chooses the criterion he wants, and then it is applied
to a few value variables (about 5 integers and about 3 doubles) in a loop (5k
to 10k iterations). FYI, the value variables are members of a structure, and
the loop is over an array of the structures. Efficiency in the loop is an
issue, so I don't want to do a lot of box-unbox operations. A one time
performance hit is ok, eg to compile the selected criterion. The obvious
advantage of compiling the criterion at runtime is that the user can twiddle
it and run it again.

So, what is a good way to arrange this? Should I make a function like below?

Public Function Qualify(byval i1 as integer, byval i2 as integer, ...) as
boolean
' the user's criterion fragment goes here
End Function

Should I then compile it and execute it? How do you execute it? Do I have
to worry about the function name (ie are there any name collision issues)?
Does the function need to be packaged (eg in a module, or shared in a class)?
Maybe I dont need a function, and instead I just want to inline compile and
execute a snippet. Can you do this? I would like to do all of this in
memory (ie I don't want to make an exe or dll file), and when the execution
iteration is done, I don't need to save anything except the results of the
selection operation.

Does anybody know how to do this kind of thing?
 
In the past, I created a template like this:

Namespace MyNamespace

Public Class MyClass

Public Override Function ToString() As String

<< put the snippet here >>

End Function

End Class

End Namespace

Then, I used the VBCodeCompiler to compile to an assembly with the "in
memory" option.

After compilation is successful, the CompilerResults class has a
property that exposes an Assembly that you can use System.Reflection on
to instantiate your class and call ToString to get the value.

You don't really need to override ToString; I just cut a corner since I
wanted to be able to call ToString on the class and not have to add more
lines of code to call the function to return the value.
 
Back
Top