VB expression trees – coalesce operator

Hey there! In this post, I’ll continue describing some of the things that are interesting about the VB compiler, especially related to expression trees and the consumption of expression trees in your LINQ provider. Again, this may not be too interesting if you aren’t writing a LINQ provider, but I hope you read on anyway…


Checking generic parameters for Nothing/null

Consider the following code fragment: Module Module1 Sub Foo(Of T)(ByVal x As T) If x Is Nothing Then End If End Sub Sub Main() Foo(10) End SubEnd Module The first thing you might ask is : “hey, how come the compiler allows me to check for Nothing? Isn’t that a reference comparison? There is no…


Using the .ToDictionary() Extension Method

Last time, I showed how you can use the Cast() extension method defined on IEnumerable/IEnumerable(Of T) to do an element conversion for a sequence that implements one of the enumerable interfaces. Today I want to talk about the ToDictionary extension method. This extension method lets you take a sequence that implements IEnumerable(Of T) and build…


Using the .Cast() Extension Method

If you take a look at the set of extension methods offered on IEnumerable (and IEnumerable(Of T)), you’ll find that there are plenty of very interesting extension methods. One of them is the Cast() extension method. What does this extension method do? It provides a way to convert an IEnumerable(Of T) to an IEnumerable(Of U)….


Understanding LINQ

Note : I plan to post this blog on the VB team blog eventually. However, because of the length and complexity, I’m posting this up on my blog for now to hopefully get some eyes on it so that I won’t make a fool of myself on the team blog 🙂 Please feel free to…


Creating a class that has an anonymous type as a field

Here’s another way to use the generic parameter trick to get an anonymous type as a field. The other day, I was trying to store the result of a lambda expression in a field, but the lambda was typed as Func(Of <anonymoustype>) and since there is no type inference for fields, and I didn’t want…


Lambda expressions article published on MSDN Magazine

Hey guys, just a quick note to let you know that my article on lambda expressions has been published on MSDN magazine. I’ll be updating this blog (actually, probably the VB team blog) with more information on lambda expressions that I didn’t have time to get into the article. Hope you enjoy! In the mean…


Partial methods for Visual Basic

One of the new features that we are adding to the language is the concept of a private partial method. In order to discover the rationale behind this feature, let’s consider a scenario where a designer generates some code and wishes to allow the user to customize certain behavior at certain points in the generated…