Created
June 29, 2010 13:21
-
-
Save jonfuller/457201 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Scratch | |
{ | |
public class Tester | |
{ | |
public class Taco<T> | |
{ | |
public T Filling { get; set; } | |
public Taco(T value) | |
{ | |
Filling = value; | |
} | |
} | |
public class Burrito<T> | |
{ | |
public T Filling { get; set; } | |
public Burrito(T value) | |
{ | |
Filling = value; | |
} | |
} | |
public class Tray<TItem1, TItem2> | |
{ | |
public TItem1 Item1 { get; set; } | |
public TItem2 Item2 { get; set; } | |
public Tray(TItem1 item1, TItem2 item2) | |
{ | |
Item1 = item1; | |
Item2 = item2; | |
} | |
} | |
#region Static Creators | |
public static class Tray | |
{ | |
public static Tray<TItem1, TItem2> Create<TItem1, TItem2>(TItem1 item1, TItem2 item2) | |
{ | |
return new Tray<TItem1, TItem2>(item1, item2); | |
} | |
} | |
public static class Taco | |
{ | |
public static Taco<T> Create<T>(T value) | |
{ | |
return new Taco<T>(value); | |
} | |
} | |
public static class Burrito | |
{ | |
public static Burrito<T> Create<T>(T value) | |
{ | |
return new Burrito<T>(value); | |
} | |
} | |
#endregion | |
public static Tray<TItem1Out, TItem2Out> ConvertTray<TItem1In, TItem1Out, TItem2In, TItem2Out>( | |
Tray<TItem1In, TItem2In> original, | |
Func<TItem1In, TItem1Out> item1Mapper, | |
Func<TItem2In, TItem2Out> item2Mapper) | |
{ | |
return Tray.Create( | |
item1Mapper(original.Item1), | |
item2Mapper(original.Item2)); | |
} | |
public void Scratch() | |
{ | |
var quesoTaco = Taco.Create(new ChickenQueso()); | |
var fajitaTaco = Taco.Create(new SteakFajita()); | |
var withTacos = Tray.Create(quesoTaco, fajitaTaco); | |
// would be nice to only have to specify Burrito.Create once ;) | |
// I think _THIS_ is the part C# won't let me do | |
var withBurritos = ConvertTray(withTacos, Burrito.Create, Burrito.Create); | |
} | |
} | |
public class SteakFajita{} | |
public class ChickenQueso{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment