Programming

Linq Style Mapping for Single Objects

Posted on

Linq is not just the go-to .NET library for handling IEnumerable data sources, it’s the inspiration for many successful and unsucessful attempts to reproduce the style in other languages. When you have a class full of Linq and you find yourself wanting to simply map a single object to something else, you’ll find yourself writing […]

Programming

Shorten Your Linq Expressions

Posted on

There is an interesting style of Linq expression that I am seeing a lot in code, including open source projects. It isn’t a big deal, but it damages readability. It looks like this: var result = someEnumerable.Where(e => e.IsCondition).FirstOrDefault(); var result = someEnumerable.Where(e => e.IsCondition).SingleOrDefault(); var result = someEnumerable.Where(e => e.IsCondition).Count(); Can you spot it? […]

Programming

Get Argument Values From Linq Expression

Posted on

If you even find yourself unpacking an expression in C#, you might find this useful. I found myself in need of obtaining a list of argument values from within an Expression expression that sometimes had chained method calls. For example, I needed to be able to get the arguments from all of the following… SomeMethod(() […]

Programming

Real Linq Style Operations Using ECMAScript 6

Posted on

There have been a few attempts to create versions of .NET’s LINQ extensions to JavaScript and TypeScript, but most of them involve operating on an array and returning an array. To be clear, it involves evaluating the result of the expression immediately and giving back the whole result immediately. This isn’t really analogous for LINQ, […]