SimBu

Returning a cast result from a generic method.

I recently needed to cast an object from the Enterprise Library Caching block back to a type, but start getting the popular System.NullReferenceException error in my tests if the value returned from the caching block was null. The problem is that you cannot cast null back to a non-nullable type like an int. The answer […]

Create your own visual studio output window.

It can be handy to write messages to custom output window/s… Here is some code to do that: Usage EnvdteHelpers.WriteMsgToCustomPane(“WCF”, “Hello”); Helper public static class EnvdteHelpers { private static OutputWindowPane _outputWindowPane; private static OutputWindowPane OutputWindowPane(string paneName) { return _outputWindowPane ?? (_outputWindowPane = CreateOutputWindowPane(paneName)); } private static OutputWindowPane CreateOutputWindowPane(string paneName) { var dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject(“VisualStudio.DTE”); var […]

Lazy load property the resharper way.

Just some more reshaper magic… Resharper took this public IThing Thing { get { if (_thing == null) _thing = new Thing(); return _thing; }} and re-factored it to this which is obvious when u look at it… public IThing Thing { get { return _thing ?? (_thing = new Thing()); }}