Geeks With Blogs
.Nettuce Code Salad February 2013 Entries
Arguments to DTO Parser for Console Applications
public static class ArgumentParser<T> where T : class, new() { delegate bool TryParseFunc<TProperty&g... input, out TProperty output); public static T Parse(string[] args, params Expression<Func<T, object>>[] propertiesToSet) { var target = new T(); var propertyList = propertiesToSet.ToList(); for (var i = 0; i < args.Count(); i++) { var property = propertyList[i]; var propertyName = PropertyName(property); var arg = args[i]; var returnType = typeof(T).GetProperty(prope... ......

Posted On Wednesday, February 20, 2013 2:34 PM

Freelance C# .NET and Web Developer in Cambridge
It's time to start looking for the next gig; please get in touch if there's anything I can help you with

Posted On Wednesday, February 20, 2013 9:32 AM

TryParse Extensions
public static class TryParseExtensions { delegate bool TryParseFunc<T>(string input, out T output); static readonly ConcurrentDictionary<Type, Delegate> Delegates = new ConcurrentDictionary<Type, Delegate>(); static TryParseExtensions() { CacheTryParseFor<bool>... CacheTryParseFor<byte>... CacheTryParseFor<DateTim... CacheTryParseFor<decimal... CacheTryParseFor<double&... CacheTryParseFor<Int16&g... ......

Posted On Tuesday, February 19, 2013 9:28 PM

Caching Set and Get Expressions
public static class ExpressionCache { static readonly ConcurrentDictionary<str... Action<object, object>> Setters = new ConcurrentDictionary<str... Action<object, object>>(); static readonly ConcurrentDictionary<str... Func<object, object>> Getters = new ConcurrentDictionary<str... Func<object, object>>(); public static void SetProperty(this object obj, string propertyName, object value) { CreateSetter(obj, propertyName).Invoke(obj, value); } public ......

Posted On Tuesday, February 5, 2013 4:02 PM

HttpContext with mock IPrincipal
public static class HttpContextBuilder { public static HttpContext Build(string userName = null, string url = null) { var httpContext = new HttpContext(new HttpRequest("", url ?? "http://test", ""), new HttpResponse(new StringWriter())); if (!userName.IsNullOrWhiteSpa... { var principal = Substitute.For<IPrincipa... principal.Identity.Name.Ret... httpContext.User = principal; } return httpContext; } } ......

Posted On Friday, February 1, 2013 4:06 PM

Copyright © Jon Canning | Powered by: