Can .NET dissemblers like Reflector access the comments in the origial source code?
Asked Answered
T

4

8

the comments are not XML comments, just normal comments

Tremblay answered 23/9, 2010 at 6:24 Comment(1)
XML comments are called XML Documentation Comments.Denoting
V
17

No. Comments are ignored by the compiler and have no representation in the assembly.

Valgus answered 23/9, 2010 at 6:25 Comment(7)
Do you mean an assembly actually does not carry any information related to the comments? Or it carries the information but it's not accessable?Tremblay
Source code is for humans. Assemblies are for machines. There are no comments in an assembly.Denoting
@AMissico: Hi an assembly does not need comments, but it can still carry the comments as part of the program?Tremblay
@user370401 No it cannot. There is no IL instruction for "comment".Leftover
@user370401: The comments are NOT in the assembly. If you don't generate an XML-Comment file and deliver it with the assembly, the comments won't be accessible.Incapable
@user370401. No. Comments are ignored, are not parsed, by the compiler. Therefore, there are absolutely no comments, no comment information, nothing even remotely associated with comments, in an assembly. Comments are only in source code.Denoting
@user370401 I'll give you ALL my reputation points if you ever happen to find any comment-derived information in any part of a standard .NET assembly. Bible code style statistical shenanigans are exempt.Valgus
M
6

A disassembler can't get the original source code. It will only create source code that does the same thing as the original source code.

As comments doesn't result in any instructions in the program, they can't be recreated from the compiled code.

Madrigal answered 23/9, 2010 at 6:35 Comment(4)
+1 good point stressing the fact that the source is recreated from the assembly.Conventioner
Simple example being the names of local variables - Reflector generally has to make them up.Linnette
I cannot agree the disassembler cannot get to the source code, but only make up code to achieve the same function. The evidence is the order of certain statements. If the disassembler could not get to the source code, there is no way it can come up with exactly the same satements with the same order. Maybe it has some difficulty getting to the names of the variables but it surely can see each and every statement.Tremblay
@user370401: The disassembler only has access to the compiled code, which is the instructions to do what the source code describes. The disassembler can only create code that describes what the instructions do, not the original description. If you for example compile a statement like int x = 1 + 2 + 3; and disassemble that, you will get int x = 6; as that is what the compiled instructions do.Madrigal
S
1

Just to add to Marks answer - the XML comments / docstrings found in the source code are also not written to the assembly, and so are also inaccessible using Reflector.

The XML comments are written to a separate xml file which the Visual Studio IDE needs access to in order to be able to supply these comments in intellisense.

Starobin answered 23/9, 2010 at 6:40 Comment(2)
XML comments are called XML Documentation Comments.Denoting
Just to be pedantic, if you have them in the right place the extracted XML Documentation Comments can be included in Reflector's display. It is not due to anything in the assembly itself though.Purpure
D
1

No it won't read the commented line from Source Code

Deductible answered 23/9, 2010 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.