using System.Collections.Generic;
public interface IConvertibleThing
IConvertedThing Convert();
public interface IConvertedThing
public class ConvertibleThing : IConvertibleThing
public IThing Thing { get; set; }
public ConvertibleThing(IThing thing)
public IConvertedThing Convert()
public class ConcreteThing : IThing
public class ConvertedThing : IConvertedThing
public static class ConversionExtensions
private static Dictionary<Type,Func<IThing,IConvertedThing>> vmt = new Dictionary<Type,Func<IThing,IConvertedThing>>();
public static void RegisterConverter(this Type type, Func<IThing,IConvertedThing> func)
public static IConvertedThing Convert(this IThing source)
return vmt[source.GetType()](source);
static public void Main(string[] args)
typeof(ConcreteThing).RegisterConverter( x => new ConvertedThing() );
IThing thing = new ConcreteThing();
IConvertibleThing convertibleThing = new ConvertibleThing(thing);
IConvertedThing convertedThing = convertibleThing.Convert();