ファイル システムへのアクセスを回避したい (できれば排除したい) 環境で、.net と codedom を使用しています。
私の現在のコード:
Private Sub ProcessCommand(ByVal command As String)
Dim MyProvider As New VBCodeProvider
Dim cp As New CompilerParameters
cp.GenerateExecutable = True
cp.GenerateInMemory = True
Dim TempModuleSource As String = command
cp.ReferencedAssemblies.Add("System.dll")
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll")
cp.IncludeDebugInformation = False
Dim cr As CompilerResults = MyProvider.CompileAssemblyFromSource(cp, TempModuleSource)
If cr.Errors.Count > 0 Then
Throw New ArgumentOutOfRangeException("Invalid Expression - please use something VB could evaluate")
Else
cr.CompiledAssembly.EntryPoint.Invoke(Nothing, Nothing)
End If
End Sub
GenerateInMemory = True が実際にはメモリ内に生成されないことに驚きました。代わりに、バイナリがコンパイルされ、一時ファイルに保存されました。コードダムに出力をメモリに保存させる方法はありますか? おそらくバイナリが一時ファイルを使用しないようにすることでしょうか?