Skip to content

Instantly share code, notes, and snippets.

@davidwhitney
Created April 4, 2011 17:09
Show Gist options
  • Save davidwhitney/901990 to your computer and use it in GitHub Desktop.
Save davidwhitney/901990 to your computer and use it in GitHub Desktop.
Give me a cup of T, of T, of T, of T, of T
class Program
{
static void Main(string[] args)
{
var animal = new Chicken {Property = "a guid! " + Guid.NewGuid()};
var myself = animal.Something(animal);
Console.WriteLine(myself.Property);
myself.Action(chick => Console.WriteLine(chick.Property));
var funkyChicken = myself.Funcy(() => new Chicken { Property = "another guid! " + Guid.NewGuid() });
Console.WriteLine(funkyChicken.Property);
myself.SomeShit(x => x.Property);
Console.ReadLine();
}
}
public abstract class Animal<T> where T: Animal<T>
{
public string Property { get; set; }
public T Something(T someOtherT)
{
return someOtherT;
}
public T Funcy(Func<T> func)
{
return func();
}
public abstract void Action(Action<T> action);
public abstract void SomeShit<TSomethingElse>(Func<T, TSomethingElse> func);
}
public class Chicken: Animal<Chicken>
{
public override void Action(Action<Chicken> action)
{
action(this);
}
public override void SomeShit<TSomethingElse>(Func<Chicken, TSomethingElse> func)
{
var something = func(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment