Skip to content

Instantly share code, notes, and snippets.

@rscarvalho
Created February 17, 2011 21:53
Show Gist options
  • Save rscarvalho/832802 to your computer and use it in GitHub Desktop.
Save rscarvalho/832802 to your computer and use it in GitHub Desktop.
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; }
}
}
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];
}
}
}
}
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