Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created November 3, 2009 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyZhao/224695 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/224695 to your computer and use it in GitHub Desktop.
class Program
{
static void Main()
{
Post post = null;
Blog blog = null;
UrlHelper helper = null;
CodeTimer.Initialize();
// warm up
helper.Action<HomeController>(c => c.Post(blog, post));
helper.Of<HomeController>().Action(c => c.Post, blog, post);
int iteration = 1000 * 1000;
CodeTimer.Time("Lambda Expression", iteration,
() => helper.Action<HomeController>(c => c.Post(blog, post)));
CodeTimer.Time("Fluent Interface", iteration,
() => helper.Of<HomeController>().Action(c => c.Post, blog, post));
Console.WriteLine("press enter to exit...");
Console.ReadLine();
}
}
public static class UrlHelperExtensions
{
public static ActionOf<TController> Of<TController>(this UrlHelper helper) where TController : new()
{
return new ActionOf<TController>(helper);
}
public static string Action<TController>(this UrlHelper helper, Expression<Action<TController>> aciton)
{
return null;
}
}
public class ActionOf<TController> where TController : new()
{
public ActionOf(UrlHelper urlHelper)
{
this.m_urlHelper = urlHelper;
}
public UrlHelper m_urlHelper;
private static TController prototype = new TController();
public string Action<T1, T2>(Func<TController, Func<T1, T2, ActionResult>> action, T1 arg1, T2 arg2)
{
return Action(action(prototype).Method, new object[] { arg1, arg2 });
}
public string Action<T1>(Func<TController, Func<T1, ActionResult>> action, T1 arg1)
{
return null;
}
public static string Action(MethodInfo methodInfo, object[] args)
{
return null;
}
}
public class ActionResult { }
public class UrlHelper { }
public class Blog{}
public class Post{}
public class HomeController
{
public ActionResult Post(Blog blog, Post post)
{
return null;
}
public ActionResult Detail(long id)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment