View on GitHub

Happil

A Reflection.Emit wrapper for dynamic implementation of interfaces and abstract classes, which just works and keeps its users happy.

Download this project as a .zip file Download this project as a tar.gz file

Welcome to Happil

In this project we aim to create a wrapper library around .NET Reflection.Emit API. The library should precisely fit two use cases of run-time type generation, which we have in mind:

We also have two important qualities in mind:

Alternatives to Happil

The motivation to launch this project comes from our experience trying to get things done with existing alternatives, namely:

Show Me The Money

Three - given an interface of a data transfer object:

public interface ICustomer
{
  int Id { get; set; }
  string FullName { get; set; }
  string EmailAddress { get; set; }
}

Two - plus an implementation convention:

DeriveClassFrom<object>()
  .ImplementInterface<ICustomer>()
  .AllProperties().ImplementAutomatic();

One - plus a decorator convention:

public class DataContractDecorator : ClassDecoratorBase
{
  public override void OnClassType(ClassType classType, ClassWriterBase writer)
  {
    writer.Attribute<DataContractAttribute>(values => values.Named(a => a.Namespace, "http://mydto/customer"));
  }
  public override void OnProperty(PropertyMember member, Func<PropertyDecorationBuilder> decorate)
  {
    decorate().Attribute<DataMemberAttribute>();
  }
}

GO!

[DataContract(Namespace = "http://mydto/customer")]
public sealed class CustomerDto : ICustomer
{
    private int m_Id;
    private string m_FullName;
    private string m_EmailAddress;

    [DataMember]
    public int Id
    {
        get { return this.m_Id; }
        set { this.m_Id = value; }
    }

    [DataMember]
    public string FullName
    {
        get { return this.m_FullName; }
        set { this.m_FullName = value; }
    }

    [DataMember]
    public string EmailAddress
    {
        get { return this.m_EmailAddress; }
        set { this.m_EmailAddress = value; }
    }
}