Skip to content

Instantly share code, notes, and snippets.

@jbrestan
Last active September 22, 2015 16:12
Show Gist options
  • Save jbrestan/be72abc6abf8bd5f1337 to your computer and use it in GitHub Desktop.
Save jbrestan/be72abc6abf8bd5f1337 to your computer and use it in GitHub Desktop.
public IDictionary<string, TValue> Dict<TValue>(
params Func<dynamic, TValue>[] pairs)
{
return pairs.ToDictionary(pair => pair.Method.GetParameters()[0].Name,
pair => pair(null));
}
void Main()
{
// Classic way
var d2 = new Dictionary<string, string>
{
{"foo", "bar"},
{"omg", "1"}
};
// "Literal"
var d = Dict(
foo => "bar",
omg => 1.ToString()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment