Calling Extension Methods on Null Objects

One of the gotchas for Extension Methods is that it’s legal to call them on Null References.  This isn’t really surprising when you think about the feature.  Boiled down to a fundamental level, extension methods are just syntactic sugar for calling a static method and automatically passing the first parameter [1].  However it can catch…


Tuples in PowerShell

Tuples in computer science are usually light weight record objects with simple name value pairs.  In scripting languages it is very handy to create them on the fly.  For quite some time I was using associative arrays in PowerShell to do just that.  PS>$a = @{Name=”MyName”;Value=”MyValue”} It has essentially everything you would need from a…


Piping elements of a String

Quick script that will allow you to pipe each char in a String into the PowerShell pipeline.  function PipeStringChar() { param ( [string]$toPipe ) for ( $i = 0; $i -lt $toPipe.Length; $i++ ) { write-output $toPipe[$i] } } Alternatively you can do this by using the ToCharArray method.  However this will create a new…


Type Inference and IEnumerable

This is somewhat of a follow up on a previous post I did on the difference between IEnumerable(Of T) and the IEnumerable interfaces.  I’ve seen several people type in the following code and wonder if there was a fundamental bug in the type inference code. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)…


AutoSize and DockStyle.Fill don’t mix

The title of this post essentially says it all.  AutoSize and DockStyle.Fill don’t mix well together.  Both properties exist to describe the size relationship relative to the rest of the control but they do so in conflicting ways. AutoSize is a property describing the size of a control relative to it’s contents.  Setting this to…


VS2008 Ships

Orcas has shipped 🙂


Lambda Unexpected Behavior

One item you strive to avoid when you design and implement a feature is unexpected behavior.  Unfortunately there is one case we couldn’t avoid with Lambda’s in VB9.  I just ran into the this problem when coding up a handler.  I wanted to disable a button when the text of particular TextBox was empty.  I…


Extension Methods without 3.5 Framework

For a time I’ve been avoiding extension methods.  Not because I’m opposed to using them but because of the 3.5 Framework.  A lot of the tools I own are designed to be very light weight tools that only require the user to have 2.0 installed on their machine.  I find that the easier that tools…


Names of Anonymous Type Members

Recently I was asked how can you get a list of anonymous type member names given a query of anonymous types.  The quick answer is that you can use a quick bit of reflection to get back the names.  Public Function GetAnonymousTypeMemberNames(Of T)(ByVal anonymousType As T) As List(Of String) Dim type = GetType(T) Dim list…