Monday 11 June 2012

1 line to compile, create and execute: O2 Script to use Roslyn to Dynamically compile and execute a method

Using the code sample from Loading an assembly generated by the Roslyn compiler here is how to write it using O2's Roslyn API.

Version 3 (doing it all in 1 line : ) )

Version 1 (replicating the original script with some error detection):

Code Samples

Version 1:

Version 2 (simpler with no error handling):

Version 3 (in one line):