Introduction

This is a .NET library that allows you to create methods and types at run-time using an easy-to-use, fluent API that looks a bit like BASIC.

It was originally presented on codeproject: http://www.codeproject.com/Articles/604301/Fluent-Method-and-Type-Builder.

This repository contains the latest releases and documentation for the library.

NuGet

It's also available as a nuget package:

 PM> Install-Package Pfz.TypeBuilding

Quick Example

Generate a dynamic method that will read a text file and write all non-empty lines to the console:

string fileName = null;
string line = null;
StreamReader streamReader = null;

Action<string> method = 
  new FluentMethodBuilder(typeof(void)).
  AddParameter(() => fileName).
  AddLocal(() => streamReader).
  AddLocal(() => line).
  Body.
    Using(() => streamReader, () => new StreamReader(fileName)).
      Loop().
        Assign(() => line, () => streamReader.ReadLine()).
        If(() => line == null).
          Break().
        EndIf().
        If(() => line.Length > 0).
          Do(() => Console.WriteLine(line)).
        EndIf().
      EndLoop().
    EndUsing().
  EndBody().
  Compile<Action<string>>();

method(@"Test.txt");

Last edited Dec 13, 2013 at 1:00 AM by zastrowm, version 7