Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created April 16, 2011 02:42
Show Gist options
  • Save takeshik/922806 to your computer and use it in GitHub Desktop.
Save takeshik/922806 to your computer and use it in GitHub Desktop.
// From Achiral.Make.Dictionary (modified)
/// <see>http://blogs.wankuma.com/mayuki/archive/2007/12/06/111901.aspx</see>
public static Dictionary<String, Object> Dictionary(params Expression<Func<Object, Object>>[] exprs)
{
return exprs.ToDictionary(expr => expr.Parameters[0].Name, expr => expr.Compile().Invoke(null));
}
var o = (IDictionary<String,Object>) new ExpandoObject();
Dictionary(a => 123, b => "foo").ForEach(_ => o.Add(_.Key, _.Value));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment