Created
February 17, 2011 21:53
-
-
Save rscarvalho/832802 to your computer and use it in GitHub Desktop.
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
using com.example.mixin; | |
namespace com.example.data | |
{ | |
public class Mixed1 : IMixin | |
{ | |
public Dictionary<string, object> Property { get; set; } | |
} | |
public class Mixed1 : IMixin | |
{ | |
public Dictionary<string, object> Property { get; set; } | |
} | |
} |
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
namespace com.example.mixin | |
{ | |
public interface IMixin | |
{ | |
public Dictionary<string, object> Property { get; set; } | |
} | |
public static class MixinMethods | |
{ | |
public static object ReturnObject(this IMixin self) | |
{ | |
return self; | |
} | |
public static void Merge(this IMixin self, IMixin other) | |
{ | |
foreach(string k in other.Property.Keys) | |
{ | |
self.Property[k] = other.Property[k]; | |
} | |
} | |
} | |
} |
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
using com.example.mixin; | |
using com.example.data; | |
namespace com.example.main | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Mixed1 m1 = new Mixed1(); | |
Mixed2 m2 = new Mixed2(); | |
m1.Property = new Dictionary<string, object>(); | |
m2.Property = new Dictionary<string, object>(); | |
m1.Merge(m2); | |
Console.WriteLine(m1.ReturnObject()); | |
Console.WriteLine(m2.ReturnObject()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment