more mucking about with hashes...

So, I got a comment on the last post about hashesfrom
lambdas (from Andrey
Shchekin)... It pointed out the fact that you don't need to
use expressions at all... which hilights an observation that I
hadn't made myself - such that the lambda parameter
names are available in the generated delegate... which of
course makes perfect sense!

So given:

Func func = Name => "Value";

You can get the lambda parameter "Name" from the function
delegate by calling:

func.Method.GetParameters()[0].Name (would
return "Name")

Here's the revised Hash method from Andrey:

public Dictionary Hash(params
Func[] args)

where T : class

{

var items = new Dictionary<>
T>();

foreach (var func in args)

{

var item =
func(null);

items.Add(func.Method.GetParameters()[0].Name, item);

}

return items;

}

very elegant and simple :)

He even did some stats, which I suspect are probably a lot more
accurate then my inital observations:

For 10000 consecutive calls:

WithAdd

10.0144ms

WithLambdas

9713.968ms

WithLambdasConstantsOnly

240.3456ms

WithDelegates

30.0432ms

Now what about multiple parameters... so far I can't think
of any uses I would have for it... perhaps a 2 level configuration
dictionary?