For a scripting engine I try to integrate C# into F# Interactive so that I can declare C#-classes inside of F# Interactive. I've managed to compile C#-code into a System.Reflection.Assembly object using Microsoft CSharp Code Provider (see below if you are interested in it). So assume that script is a System.Reflection.Assembly. Using
script.GetTypes()
I can get the type information for all types declared in the script, e.g. if my script is declared in the following C#-code :
let CS_code="""
namespace ScriptNS
{
public class Test
{
public string AString()
{
return "Test";
}
}
}"""
script.GetTypes will contain type information for the ScriptNS.Test class. What I'd like to achieve is to use this class like any other class in F# Interactive, e.g.
let t=new ScriptNS.Test()
Hence, my question: can I somehow import the Class to the FSI AppDomain?
Thanks for your help,
Andreas
P.S. One possibility I found is to use the #r directive. A working solution would be:
open System.Reflection
open System.CodeDom.Compiler
// Create a code provider
let csProvider=new Microsoft.CSharp.CSharpCodeProvider()
// Setup compile options
let options=new CompilerParameters()
options.GenerateExecutable<-false
options.GenerateInMemory<-false
let tempfile="c:\Temp\foo.dll"
options.OutputAssembly<-tempfile
let result=csProvider.CompileAssemblyFromSource(options,CS_code)
let script=result.CompiledAssembly
#r "c:\Temp\foo.dll"
// use the type
let t=new ScriptNS.Test()
However, I'm not happy with the additional dll.