How to implement left join in JOIN Extension method

Normally left joins in LINQ are modelled with group joins, sometimes in conjunction with DefaultIfEmpty and SelectMany: var leftJoin = p.Person.Where(n => n.FirstName.Contains(“a”)) .GroupJoin(p.PersonInfo, n => n.PersonId, m => m.PersonId, (n, ms) => new { n, ms = ms.DefaultIfEmpty() }) .SelectMany(z => z.ms.Select(m => new { n = z.n, m })); That will give a … Read more

Code equivalent to the ‘let’ keyword in chained LINQ extension method calls

Let doesn’t have its own operation; it piggy-backs off of Select. You can see this if you use “reflector” to pull apart an existing dll. it will be something like: var result = names .Select(animalName => new { nameLength = animalName.Length, animalName}) .Where(x=>x.nameLength > 3) .OrderBy(x=>x.nameLength) .Select(x=>x.animalName);

Why doesn’t VS 2008 display extension methods in Intellisense for String class

It’s by explicit design. The problem is that while String most definitely implements IEnumerable<T>, most people don’t think of it, or more importantly use it, in that way. String has a fairly small number of methods. Initially we did not filter extension methods off of String and the result was a lot of negative feedback. … Read more

How to use Active Support core extensions

Since using Rails should handle this automatically I’m going to assume you’re trying to add Active Support to a non-Rails script. Read “How to Load Core Extensions“. Active Support’s methods got broken into smaller groups in Rails 3, so we don’t end up loading a lot of unneeded stuff with a simple require ‘activesupport’. Now … Read more

Using extension methods in .NET 2.0?

Like so: // you need this once (only), and it must be in this namespace namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] public sealed class ExtensionAttribute : Attribute {} } // you can have as many of these as you like, in any namespaces public static class MyExtensionMethods { public static int MeasureDisplayStringWidth ( … Read more