Accessing .Net’s Opensource Code Via ReSharper in Visual Studio
TLDR: Alt+` and select “Sources From Symbol File”.
I love working with other programmers. Especially other programmers who know more than me (not particularly hard to find).
I would love to do a project or part of a programming XP or paired – it hasn’t happened yet, but who knows. The career is still young… kinda…
Anyway, the great thing about working with other people is you can learn so much from them. For example, something that might seem incredibly obvious to them, might not have occurred to you. Or they might have a few tricks up their sleeve that wouldn’t come up in conversation, or that they might not even realise aren’t common knowledge.
Obviously, the opposite is also true and sometimes you can impart some of your wisdom on to someone else!
At work the other day, this exact thing happened. Here’s the context.
I was making an optional parameter for a method. I wanted the default value to the empty string.
public void DoSomething(string aString = “”)
public void DoSomething(string aString = String.Empty)
Well the compiler is telling me the default value needs to be a constant. Surely String.Empty is a constant, right?
Thinking this was an interesting little tidbit I’d stumbled across, I posed this question to my mate (let’s call him “Adam”) who didn’t know why it would be a problem off the top of his head. We joked that it’s probably something only Skeet would know (which is actually a really nerdy joke in hindsight). Then Adam suggested we look at the source code implementation for String.Empty.
On his keyboard he hits Alt+` and selects “Sources From Symbol File”.
We can now view the implementation of String.Empty and see it’s static readonly in oppose to a const a compile time constant. The difference being that a const is an unchanging value that we know won’t change and are able to drop those zeros and ones into the compiled output. A readonly can be set in a constructor or to something like DateTime.Now. Here’s an excellent explanation.
Now, I knew the framework was opensource, but had no idea it was so easily accessed via ReSharper and Visual Studio. This is an awesome feature that I will be using a lot more of in the future, and I believe will make me a better programmer.
Adam thought this was common knowledge and would never have mentioned it, if it hadn’t come up randomly.
Long live smart guys!
So, this idea of learning by simply working with other humans-beings is a great one, and I imagine it holds true for all professions, or disciplines, not just software development.
As an aside, this reminds me of a recent-ish post by Old Faithful (Aka Scott Hanselman) who encourages us to look under the hood more often: