Skip to content

Instantly share code, notes, and snippets.

@shanefulmer
shanefulmer / gist:3150495
Created July 20, 2012 12:33
Dynamic Dispatch 1
using System;
using System.Collections.Generic;
public class Foo { }
public class Bar { }
public class Baz { }
public class Program
{
public static void CallMe<T>(T input)
@shanefulmer
shanefulmer / gist:3150534
Created July 20, 2012 12:43
Dynamic Dispatch 2
typeof(T): System.Object
typeof(T): System.Object
typeof(T): System.Object
@shanefulmer
shanefulmer / gist:3150581
Created July 20, 2012 12:54
Dynamic Dispatch 3
using System;
using System.Collections.Generic;
public class Foo { }
public class Bar { }
public class Baz { }
public class Program
{
public static void CallMe<T>(T input)
@shanefulmer
shanefulmer / gist:3150590
Created July 20, 2012 12:56
Dynamic Dispatch 4
typeof(T): Foo
typeof(T): Bar
typeof(T): Baz
@shanefulmer
shanefulmer / gist:3150597
Created July 20, 2012 12:57
Dynamic Dispatch 5
using System;
using System.Collections.Generic;
public class Foo { }
public class Bar { }
public class Baz { }
public class Program
{
public static void CallMe<T>(T input)
@shanefulmer
shanefulmer / gist:3328690
Created August 12, 2012 01:33
Handler 1
public class Foo
{
public string Render()
{
return "this is a foo";
}
}
@shanefulmer
shanefulmer / gist:3335789
Created August 13, 2012 00:33
Handler 2
public interface ISomeService { string DoSomething(); }
public class SomeService : ISomeService { public string DoSomething() { return string.Empty; } }
public class Foo
{
private readonly ISomeService _someService;
public Foo(ISomeService someService) { _someService = someService; }
public string Render()
{
return "this is a foo" + _someService.DoSomething();
@shanefulmer
shanefulmer / gist:3335824
Created August 13, 2012 00:37
Handler 3
public interface ISomeTextService { string DoSomething(); }
public class SomeTextService : ISomeTextService { public string DoSomething() { return string.Empty; } }
public interface ISomeHtmlService { string DoSomethingElse(); }
public class SomeHtmlService : ISomeHtmlService { public string DoSomethingElse() { return string.Empty; } }
public enum RenderType {Text, Html}
public class Foo
{
private readonly ISomeTextService _someTextService;
private readonly ISomeHtmlService _someHtmlService;
@shanefulmer
shanefulmer / gist:3336101
Created August 13, 2012 01:06
Handler 4
public interface ISomeTextService { string DoSomething(); }
public class SomeTextService : ISomeTextService { public string DoSomething() { return string.Empty; } }
public interface ISomeHtmlService { string DoSomethingElse(); }
public class SomeHtmlService : ISomeHtmlService { public string DoSomethingElse() { return string.Empty; } }
public enum RenderType {Text, Html}
public interface IRenderer<T> { string Render(T obj); }
public class FooTextRenderer : IRenderer<Foo>
{
@shanefulmer
shanefulmer / gist:3336201
Created August 13, 2012 01:23
Handler 5
public class CoreRegistry : Registry
{
public CoreRegistry()
{
Scan(cfg =>
{
cfg.TheCallingAssembly();
cfg.WithDefaultConventions();
cfg.IncludeNamespaceContainingType<Foo>();
cfg.ConnectImplementationsToTypesClosing(typeof(IRenderer<>));