Using AutoMapper, I hit a place where a named argument would've fit very nicely:
.ForMember(s => s.MyProperty, opt => opt.MapFrom(s => BuildMyProperty(s, isAdvanced: false)))
But the compiler yelled at me:
An expression tree may not contain a named argument specification
So I had to revert to:
.ForMember(s => s.MyProperty, opt => opt.MapFrom(s => BuildMyProperty(s, false)))
Does anyone know why the compiler disallows named arguments in this situation?
Consider the following:
You agree I hope that the last two lines must do exactly the same thing, right? Which is to print
NM3
.Now, what expression tree library calls would you like the expression tree conversion to generate that ensure this? There are none! We are therefore faced with the following choices:
Compile
method that takes the execution order into account.x = ()=>Q(n : N(), m: M());
actually be implemented asx = ()=>Q(M(), N());
and be incompatible with the non-expression-tree version.(1) is nice, but expensive. (2) is a non-starter; we can't in good conscience introduce this kind of "gotcha". (3) is cheap but irritating.
We chose (3).