Prev | Current Page 378 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

It supports the debugger by allowing it to check that it??™s found the right
source file. Normally when a C# file is compiled, the compiler generates a checksum
from the file and includes it in the debugging information. When the debugger needs
to locate a source file and finds multiple potential matches, it can generate the checksum
itself for each of the candidate files and see which is correct.
Now, when an ASP.NET page is converted into C#, the generated file is what the C#
compiler sees. The generator calculates the checksum of the .aspx page, and uses a
Listing 7.9 Class containing an unused field
Listing 7.10 Disabling (and restoring) warning CS0169
199 Fixed-size buffers in unsafe code
checksum pragma to tell the C# compiler to use that checksum instead of calculating
one from the generated page.
The syntax of the checksum pragma is
#pragma checksum "filename" "{guid}" "checksum bytes"
The GUID indicates which hashing algorithm has been used to calculate the checksum.
The documentation for the CodeChecksumPragma class gives GUIDs for SHA-1 and
MD5, should you ever wish to implement your own dynamic compilation framework
with debugger support.
It??™s possible that future versions of the C# compiler will include more pragma
directives, and other compilers (such as the Mono compiler, mcs) could have their
own support for different features.


Pages:
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390