heredar


An attempt at multiple inheritance in .net

Uses IL weaving (via http://www.mono-project.com/Cecil) to add support for static mixins to .net languages

  • No references required
  • No base class required
  • Supports .net 3.5, .net 4, Silverlight 3, Silverlight 4 and Windows Phone 7. Even in client profile mode

Simple templates ``` public class Auditable : IAuditable { public DateTime CreateDate { get; set; } public string CreatedBy { get; set; } public DateTime UpdateDate { get; set; } public string UpdateBy { get; set; } }

public class ErrorInfo : IDataErrorInfo { public object Target { get; set; }

#region IDataErrorInfo Members

public string this[string columName]
{
    get { return Validator.Validate(Target, columName); }
}

public string Error
{
    get { return Validator.Validate(Target); }
}

#endregion

} ```

Your code

[ExtendWith(typeof(ErrorInfo), typeof(Auditable))] public class Person { public string FirstName { get; set; } public string LastName { get; set; } public DateTime Birthdate { get; set; } }

What gets compiled

``` public class Person : IAuditable, IDataErrorInfo { private Auditable Auditable_1 = new Auditable(); private ErrorInfo ErrorInfo_1 = new ErrorInfo();

public Person()
{
    this.ErrorInfo_1.Target = this;
}

public DateTime Birthdate { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }

//Auditable members

public DateTime CreateDate
{
    get
    {
        return this.Auditable_1.CreateDate;
    }
    set
    {
        this.Auditable_1.CreateDate = value;
    }
}

public string CreatedBy
{
    get
    {
        return this.Auditable_1.CreatedBy;
    }
    set
    {
        this.Auditable_1.CreatedBy = value;
    }
}

public string UpdateBy
{

    get
    {
        return this.Auditable_1.UpdateBy;
    }

    set
    {
        this.Auditable_1.UpdateBy = value;
    }
}

public DateTime UpdateDate
{
    get
    {
        return this.Auditable_1.UpdateDate;
    }
    set
    {
        this.Auditable_1.UpdateDate = value;
    }
}

//dataerror info members

public string Error
{
    get
    {
        return this.ErrorInfo_1.Error;
    }
}

public string this[string columName]
{
    get
    {
        return this.ErrorInfo_1[columName];
    }
}

} ```

Tools and products used

Project Information

Labels:
.net c