Skip to content

prescottadam/pMixins

 
 

Repository files navigation

[pMixins]

###Welcome to [pMixins]! http://pmixins.com

[pMixins] is a Mixin (http://en.wikipedia.org/wiki/Mixins) framework for C#. Mixin code is generated at design time by a Visual Studio plug-in. You can download the plug in here: https://visualstudiogallery.msdn.microsoft.com/a40fde9e-0e3f-4cdc-9c2a-af9de11695b2

Example usage:

Step 1: Define a Mixin Class that contains members that should be injected into other classes.

public class Mixin
{
  // This method should be in several class
  public void Method(){ }
}

Step 2: Define a Target (Note: This must be partial) class that should get all of Mixin's Members

[pMixin(Target = typeof(Mixin)]
public partial class Target{}

Step 3: Save Target.cs. The [pMixin] Code Generator then gets to work generating the Composition code behind the scenes. Below is a simplified version to illustrate what's going on.

public partial class Target
{
  private Mixin _compositionInstance; 
  
  public void Method()
  {
    // forward call to Mixin instance
    _compositionInstance.Method();
  }
}

Step 4: You can now create an instance of Target and call the mixed in Mixin members!

public class Consumer  
{
  public void Example()
  {
    var target = new Target();
        
    // can call mixed in method
    target.Method();
        
    // can implicitly convert Target to Mixin
    Mixin m = new Target();
    m.Method();
  }
}
 

About

pMixins - Mixin framework for C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.3%
  • HTML 0.8%
  • JavaScript 0.6%
  • CSS 0.2%
  • PowerShell 0.1%
  • Batchfile 0.0%