Skip to content

Instantly share code, notes, and snippets.

View thunklife's full-sized avatar

Jesse Williamson thunklife

View GitHub Profile
@thunklife
thunklife / Person.cs
Created December 27, 2011 17:29
Basic Person Class
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public override string ToString()
{
return string.Format("{0} {1} {2}", FirstName, MiddleName, LastName);
}
@thunklife
thunklife / Person.DSL.cs
Created December 27, 2011 17:30
Simple DSL for building up a Person
public static class PersonFactory
{
public static FirstNameExpression CreatePerson()
{
return new FirstNameExpression(new Person());
}
}
public class FirstNameExpression
{
@thunklife
thunklife / FluentTreeView.cs
Created December 27, 2011 17:31
MVC Tree View alternative using ExpressionBuilder objects
public static class FluentTreeViewHelper
{
/// <summary>
/// Create an HTML tree from a recursive collection of items
/// </summary>
public static FluentTreeView<T> FluentTreeView<T>(this HtmlHelper html, IEnumerable<T> items)
{
return new FluentTreeView<T>(html, items);
}
}
var myPerson = PersonFluentFactory.Init().Create();
@thunklife
thunklife / Program.cs
Created December 27, 2011 19:52
Building up a Person fluently
static void Main(string[] args)
{
Person tom = PersonFactory
.CreatePerson()
.WithFirstName("Tom")
.WithMiddleName("Paul")
.WithLastName("Smith");
}
public static class PersonFactory
{
public static FirstNameExpression CreatePerson()
{
return new FirstNameExpression(new Person());
}
}
public class FirstNameExpression
{
@thunklife
thunklife / DisplayModeExpression.cs
Created April 25, 2012 18:58
Display Mode Provider DSL For Fun
public class DisplayModeExpression
{
readonly Func<HttpContextBase, bool> _condition;
public DisplayModeExpression(Func<HttpContextBase, bool> condition)
{
_condition = condition;
}
public void UseDisplayMode(string displayModeSuffix)
@thunklife
thunklife / CallingProgram.cs
Created July 20, 2012 20:38
Generic FitBitClient Methods
class Program
{
static void Main(string[] args)
{
var client = new FitBitClient(); //pretending there are no dependencies for brevity.
var user = client.Get<UserProfile>(new GetUserProfileRequest("someUser"));
}
}
@thunklife
thunklife / MappingTest.cs
Created September 24, 2012 14:05
Mapping a Collection of Interfaces With Their Own Unique Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using NUnit.Framework;
namespace InterfaceMapping
{
[TestFixture]
@thunklife
thunklife / ExquisiteCorpseRegistry.cs
Created January 13, 2013 16:59
Me failing at getting FubuMVC to run.
using ExquisiteCorpse.Web.Home;
using FubuMVC.Core;
namespace ExquisiteCorpse.Web
{
public class ExquisiteCorpseRegistry : FubuRegistry
{
public ExquisiteCorpseRegistry()
{
Actions