Monthly Downloads: 233
Programming language: C#
License: Copyright 2016
Tags: Generation     Roslyn     Code     Compilers    

Testura.Code alternatives and similar packages

Based on the "Compilers, Transpilers and Languages" category

  • P

    P is a language for asynchronous event-driven programming.
  • PeachPie

    PeachPie is a PHP compiler and runtime for .NET and .NET Core, which allows entire PHP applications to run on the modern, secure and performant .NET and .NET Core platforms.
  • Iron python

    A python 2 implementation that is integrated with the dot net framework.
  • Mond

    A dynamically typed scripting language written in C# with a REPL, debugger, and simple embedding API.
  • Hybridizer

    CIL (C#, VB.Net, F#) to CUDA compiler. [$]
  • Amplifier.NET

    Write and compile your own kernel function using C# and Amplifier will take care of running it on your favorite hardware. Amplifier allows .NET developers to easily run complex applications with intensive mathematical computation on Intel CPU/GPU, NVIDIA, AMD without writing any additional C kernel code.

Do you think we are missing an alternative of Testura.Code or a related project?

Add another 'Compilers, Transpilers and Languages' Package


Testura Logo

Testura.Code is a wrapper around the Roslyn API and used for generation, saving and compiling C# code. It provides methods and helpers to generate classes, methods, statements and expressions.

It provide helpers to generate:

  • Classes
  • Methods
  • Parameters
  • Arguments
  • Attributes
  • Fields
  • Properties

But also simple statements like:

  • Declaration statements (for example declare and assign variables)
  • Iterations statements (for example for-loop)
  • Jump statements (for example return)
  • Selection statement (for example if-statements)
  • Expression statements (for example invoke methods)


NuGet NuGet Status


PM> Install-Package Testura.Code


Testura.Code have three different types of helpers:

  • Generators - The most basic kinds of code generators, for example fields, properties and modifiers.
  • Statement - Helpers for regular statements and expressions, for example declare and assign a variable or invoke a method.
  • Builders - Currently we have two builder - One class builder and one method builder. These have the highest abstraction and are easy to use.



Hello world

Here is an example on how to generate, save and compile a simple hello world.


var @class = new ClassBuilder("Program", "HelloWorld")
        new MethodBuilder("Main")
        .WithModifiers(Modifiers.Public, Modifiers.Static)
        .WithParameters(new Parameter("args", typeof(string[])))
                Statement.Expression.Invoke("Console", "WriteLine", new List<IArgument>() { new ValueArgument("Hello world") }).AsStatement(),
                Statement.Expression.Invoke("Console", "ReadLine").AsStatement()

This code will generate following code:

using System;

namespace HelloWorld
    public class Program
        public static void Main(String[] args)
            Console.WriteLine("Hello world");


var saver = new CodeSaver();

// As a string
var generatedCode = saver.SaveCodeAsString(@class);

// Or to file
saver.SaveCodeToFile(@class, @"/path/HelloWorld.cs");


var compiler = new Compiler();

//To a dll

// From string
var result = await compiler.CompileSourceAsync(@"/path/HelloWorld.dll", generatedCode);

// From file
var result = await compiler.CompileFilesAsync(@"/path/HelloWorld.dll",  @"/path/HelloWorld.cs");

//In memory (without creating a dll)

// From string
var result = await compiler.CompileSourceInMemoryAsync(generatedCode);

// From file
var result = await compiler.CompileFilesInMemoryAsync(@"/path/HelloWorld.cs");

Missing anything?

If we miss a feature, syntax or statements - just create an issue or contact us and I'm sure we can add it.

It is also possible for you to contribute with your own feature. Simply add a pull request and we will look at it.


This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.


Visit www.testura.net, twitter at @testuranet or email at mille.bostrom@testura.net

*Note that all licence references and agreements mentioned in the Testura.Code README section above are relevant to that project's source code only.