Using Ternary As Match With
One of the things I particularly like with Caml is match ___ with
value operator. It is kind of a switch case
, except that it has a value rather than being a masked big if then else
.
tuffEnumType.HugelyFantasticStuff ? context.Solid.ID
: Guid.Empty;
The closest thing I found in C# is using the ternary operator in this fashion, which is kind of elegant IMNSHO:
Func<ShittyType, Guid> stuffIdSelector =
type =>
type == EnumStuffEnumType.BigStuff ? context.BigStuff.ID
: type == EnumS
That you would then use for example in a nice
var ids = stuffList.Select(stuffIdSelector);
Not exactly the same, but close enough, and with pattern matching coming in C# 6, exciting things ahead!