c#.net source code - c#

is it possible to see the source code of C# library implementations?
such as List or Dictionary implementation source code.

You can download the entire Microsoft .NET Framework Sourcecode at Microsoft's Reference Source Code Center.

You should be able to open up anything in Reflector (http://www.red-gate.com/products/reflector/) and view any of the framework source.

Yes. ReSharper helps by automatically downloading the pdb, if it is availabe from Microsoft, when you hit F12. Otherwise you can use Reflector.

Use this:
http://www.red-gate.com/products/reflector/
There is a free version.
There are other ways, like the Mono or Rotor source. In my opinion, Reflector is the simplest and most useful.

Yes, it is. You can decompile every .NET Assembly using Red Gates Reflector together with the appropriate AddIns.

You can use reflector for this

If you want to go one step further than reflector and actually step into the framework code while debugging, then check out this blog post from Scott Guthrie: .NET Framework Library Source Code now available.
It tells you how to use the Microsoft Symbol servers to get the framework code while debugging.

Related

how to get source code from dll in C#

I have an assembly which is not strong-named. I have no source code for it.
I now need to recover the source code . Is there a way to do this?
Use decompiler such as dotPeek or ILSpy.
Be aware of the fact that code is decompiled using IL code that resides in .NET assembly it may be different from the original code used when compiling the assembly.
I can recommend RedGate .NET Reflector. You can try 14 days trial version.
At work we used to use Reflector, until we learned that dotPeek is free. It serves us well.

Is that possible to extract C# source code from Winforms application exe file

Can someone tell me if it is possible to view source code only using exe file. For example I have made project and in debug there is exe file so if I'll send this to someone he will be able to view it's source code(Using hacking tolls or by something)?
The answer is Yes
Your code can be de-compiled and can be seen.
I personally use this one for .net:
http://www.jetbrains.com/decompiler/
But it is not the only one, there are many decompilers exist.
Yep, there's Resharper or ILSpy
Certainly he/she can see your IL code, the code that has been constructed by your compiler. For instance, a tool for doing this is the MSIL Disassembler http://msdn.microsoft.com/en-us/library/f7dy01k1(v=vs.110).aspx. I suppose having the IL language it wouldn't be difficult to get the C# code.
You must use a decompiler as Net Reflector or JetBrains, anyway if your exe is obfuscated also them can not work
You can use the default ILDASM (IL disassembler) from VS command prompt.

How to compile the dll back after decompile C# dll?

I use reflector to decompile a asp.net dll, after that I find the bug and fixed it, now I want to compile it back to a dll, then I can deploy, but it seems that I can't how can I do this ?
You have two choices, either you use Reflector's addin Filedisassembler, which is free, or commercial ( and pricy) .net dissemblers such as spices.net or salamander decompiler.
I used Filedisassembler; the quality of the decompiled code is very bad. The decompiler code cannot be recompiled.
I'm sure about the quality of commercial decompilers but I suspect that it would be much better.
Edit: To use Filedisassembler, go to Reflector, View->Addins, click Add and select the Filedisassembler.dll.
If the fix is simple enough and you know IL, you are better of round tripping it using IL instead of a high-level language such as C# or VB.Net.
See search: http://www.google.com/#hl=en&q=ildasm+IL+round-tripping

.Net Assemblies Decompiler that Convert Assemblies into C# Source Code

I am well aware that one can use reflector to browse the content inside an assembly, and one can use FileDisassembler to convert the content into the c# source code with cs projects. But the source code outputted by FileDisassembler may not be able to compile if it has interface with property.
Is the other similar applications that do what FileDisassembler does?
I would not trust Reflector's decompiler.
Many times I have seen it just ignore instruction it did not understand, or just optimized certain sequences away, and changing the meaning the process.
The only trusty way is to use IL.
Regarding more tools, look at the CCI. IIRC, they had a C# source emitter at some stage, but it was removed for some reason.
dotPeek from jetBrains is a good decompiler for c#. http://confluence.jetbrains.net/display/NETPEEK/dotPeek+Early+Access+Program

How do I allow my .net program to compile C# code while running?

I've seen a couple .net applications that allow you to select a C# .cs source file and the program itself will compile this code and run it.
How is this done?
It probably uses the CSharpCodeProvider class in the Microsoft.CSharp namespace. You would want to look at the following methods to compile code:
CompileAssemblyFromDom
CompileAssemblyFromFile
CompileAssemblyFromSource
CodeDOM is your friend
MSDN has a great series of articles explaining this...
http://msdn.microsoft.com/en-us/library/650ax5cx.aspx
My guess is by explicitly calling the csc.exe compiler. Keep in mind that this and any dependencies would have to be included with your deployment.
You can take a look at CS-Script which interprets C# files. Its free but not open sources though...

Categories