Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.Diagnostics
- open System.Reflection
- open System.Text.RegularExpressions
- let pwd = System.Environment.CurrentDirectory
- let getCurrentSourceFile =
- let _base = String.concat "/" [pwd; "Testlib"]
- in (_base+".cs", _base+".dll")
- let getFileAsString filepath =
- String.concat "\n" <| System.IO.File.ReadLines(filepath)
- let writeToFile filepath contents =
- if not <| System.IO.File.Exists filepath
- then System.IO.File.WriteAllLines (filepath, contents)
- else System.IO.File.WriteAllLines (filepath, contents)
- let compileFile source target =
- let process = Process.Start("mcs", "-t:library -o:"+target+" "+source)
- process.WaitForExit()
- printfn "%d" process.ExitCode
- 0
- [<EntryPoint>]
- let main argv =
- let (source, target) = getCurrentSourceFile
- let current_source = getFileAsString source
- let tmp_path = target + ".tmp"
- let tmp_out = target + ".dll"
- writeToFile tmp_path [|current_source|]
- compileFile tmp_path tmp_out
- let DLL = Assembly.LoadFile(tmp_out)
- let Test = DLL.GetType("Test")
- let Test' = Activator.CreateInstance(Test)
- let Method = Test.GetMethod("add5")
- let x = downcast (Method.Invoke (Test', [|5|])) : int
- printfn "%d" <| x // prints 10
- 0 // return an integer exit code
- ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement