Skip to content

Instantly share code, notes, and snippets.

@moniyax
Created October 1, 2011 07:17
Show Gist options
  • Save moniyax/1255722 to your computer and use it in GitHub Desktop.
Save moniyax/1255722 to your computer and use it in GitHub Desktop.
Csharp Mixins
//Idea from: http://stackoverflow.com/questions/9033/hidden-features-of-c#238462
class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Foo().Dance());
Console.WriteLine(new Bar().Dance());
Console.ReadKey();
/*Output:
dance lomo! FooMONI
dance lomo! BarMONI
*/
}
}
class Foo: DodoMixin
{
public string Moniker
{
get
{
return "FooMONI";
}
}
}
class Bar: DodoMixin
{
public string Moniker
{
get
{
return "BarMONI";
}
}
}
public interface DodoMixin
{
string Moniker { get; }
}
public static class Woga
{
public static string Dance(this DodoMixin @this)
{
return "dance lomo! " + @this.Moniker;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment