Interesting Extension Hack To Get Around NullReferenceException's
Today I came across an interesting extension pattern that I didn’t know how the runtime would react. Normally when you do something like the following: string s = null; Console.WriteLine(s.Trim()); // throws NullReferenceException You get a NullReferenceException meaning that you didn’t first check to see if the object was null before trying to call one of its methods. This is pretty common and results in patterns that usually look like this: ...