Project Description
Simple but surprisingly powerful tool to quickly try out .NET fragments in C#, VB.NET and JScript.

Usage
Simply select the language you want to use, type in your code fragment and press F5 to run it:

Screenshot.png

Reusable library
Part of the source code is a library enabling you to create in-memory, executable assemblies. You can both capture their console-like output and the return value.

Sub Main()
   ' Create a compiler for C#. Also supports VB.NET and JScript
   Dim compiler As FragmentCompiler =
     FragmentCompiler.CreateCompiler(FragmentCompiler.LanguageTypeEnum.CSharp)
   ' Compile a source code fragment that returns something based on its arguments
   Dim c As CodeFragment = compiler.CompileExpression(
     "PrintLine(""Executed at "" + DateTime.Now.Ticks.ToString());" +
     "if (args.Length == 0) return ""Nothing to do!"";" +
     "if (args.Length == 1) return args[0];" +
     "return args.Length;"
   )
   ' If compiling succeeded, run the fragment three times and display the result
   If c.Succeeded Then
     ' No arguments --> "Nothing to do!"
     Console.WriteLine(c.Run())
     Console.Write(c.Output)
     ' A single argument --> "and a one"
     Console.WriteLine(c.Run(New String() {"and a one"}))
     Console.Write(c.Output)
     ' More than 1 argument --> "2"
     Console.WriteLine(c.Run(New String() {"one", "two"}))
     Console.Write(c.Output)
   Else
     ' On errors, dump the first error
     Console.Error.WriteLine(c.Errors(0).ErrorText)
   End If End Sub

Example: Function Plotter

A Code Fragment is also used to produce the following plot in another example program: FuncPlotter.

image

The source code for this form is approx. one printed page.

Last edited Mar 7, 2014 at 10:59 AM by mobzystems, version 20