When using .peek and [ReSharper](http://en.wikipedia.org/wiki/ReSharper) in Visual Studio (15) you can check the implementation of framework types. It will download a reference source debug file, and you can check the reference-only code.

Here's an example of a post with reference source; it's a whole file copy pasted in the end:

[Example question](https://stackoverflow.com/questions/38436847/what-does-0-on-string-format-do)

I have no idea about the legal situation, and I want to know how it is.

Is it legal to post such code on Stack Overflow if I mention where it's from and keep the copyright notices in?