Created
October 1, 2011 07:17
-
-
Save moniyax/1255722 to your computer and use it in GitHub Desktop.
Csharp Mixins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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