All Projects → Testura → Testura.code

Testura / Testura.code

Licence: mit
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.

Projects that are alternatives of or similar to Testura.code

islpy
Python wrapper for isl, an integer set library
Stars: ✭ 58 (-69.31%)
Mutual labels:  wrapper, code-generation
Fbrecog
An unofficial python wrapper for the Facebook face recognition endpoint
Stars: ✭ 184 (-2.65%)
Mutual labels:  wrapper
Libuvsharp
.NET bindings for libuv
Stars: ✭ 170 (-10.05%)
Mutual labels:  wrapper
Wiki
Wikipedia Interface for Node.js
Stars: ✭ 180 (-4.76%)
Mutual labels:  wrapper
Rocksdb Sharp
.net bindings for the rocksdb by facebook
Stars: ✭ 173 (-8.47%)
Mutual labels:  wrapper
Qt5.cr
Qt5 bindings for Crystal, based on Bindgen
Stars: ✭ 182 (-3.7%)
Mutual labels:  wrapper
React Openlayers
OpenLayer React Components
Stars: ✭ 169 (-10.58%)
Mutual labels:  wrapper
Xsd2php
Convert XSD into PHP classes and JMS serializer definitions
Stars: ✭ 190 (+0.53%)
Mutual labels:  code-generation
Jaffree
Java ffmpeg and ffprobe command-line wrapper
Stars: ✭ 184 (-2.65%)
Mutual labels:  wrapper
Nopaginate
Android pagination library (updated 01.05.2018)
Stars: ✭ 180 (-4.76%)
Mutual labels:  wrapper
Modernavplayer
ModernAVPlayer is a persistence AVPlayer wrapper
Stars: ✭ 179 (-5.29%)
Mutual labels:  wrapper
Codelingo
CodeLingo // The Linter for Devs Who Hate Linters
Stars: ✭ 174 (-7.94%)
Mutual labels:  code-generation
Re2dfa
Transform regular expressions into finite state machines and output Go source code. This repository has migrated to https://gitlab.com/opennota/re2dfa
Stars: ✭ 182 (-3.7%)
Mutual labels:  code-generation
Keras Multi Head
A wrapper layer for stacking layers horizontally
Stars: ✭ 172 (-8.99%)
Mutual labels:  wrapper
Activej
ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!
Stars: ✭ 183 (-3.17%)
Mutual labels:  code-generation
Config4k
A Kotlin wrapper for Typesafe Config
Stars: ✭ 168 (-11.11%)
Mutual labels:  wrapper
Tdl
Node.js bindings to TDLib.
Stars: ✭ 177 (-6.35%)
Mutual labels:  wrapper
Protontricks
A simple wrapper that does winetricks things for Proton enabled games, requires Winetricks.
Stars: ✭ 182 (-3.7%)
Mutual labels:  wrapper
Yasha
A command-line tool to render Jinja templates for great good
Stars: ✭ 189 (+0%)
Mutual labels:  code-generation
Godot Kotlin Native
Kotlin bindings for Godot Engine
Stars: ✭ 186 (-1.59%)
Mutual labels:  wrapper

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)

Install

NuGet NuGet Status

https://www.nuget.org/packages/Testura.Code

PM> Install-Package Testura.Code

Usage

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.

Documentation

Examples

Hello world

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

Generate

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

This code will generate following code:

using System;

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

Save

var saver = new CodeSaver();

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

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

Compile

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.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Contact

Visit www.testura.net, twitter at @testuranet or email at [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].