CHAPTER 15 TYPE REFLECTION, LATE BINDING, AND ATTRIBUTE-BASED PROGRAMMING
HashValue Blob:
Flags: [none] (00000000)
Documenting String Literals
The final point of interest regarding .NET metadata is the fact that each and every string literal in your
code base is documented under the User Strings token.
User Strings
------------------------------------------------------70000001 : (11) L"Jamming {0}"
70000019 : (13) L"Quiet time..."
70000035 : (23) L"CarLibrary Version 2.0!"
70000065 : (14) L"Ramming speed!"
70000083 : (19) L"Faster is better..."
700000ab : (16) L"Time to call AAA"
700000cd : (16) L"Your car is dead"
Note As illustrated in this last metadata listing, always be aware that all strings are clearly documented in the
assembly metadata. This could have huge security consequences if you were to use string literals to capture
passwords, credit card numbers, or other sensitive information.
The next question on your mind may be (in the best-case scenario) “How can I leverage this
information in my applications?” or (in the worst-case scenario) “Why should I care about metadata?”
To address both points of view, allow me to introduce .NET reflection services. Be aware that the
usefulness of the topics presented over the pages that follow may be a bit of a head-scratcher until this
chapter’s endgame. So hang tight.
Note You will also find a number of CustomAttribute tokens displayed by the MetaInfo window, which
documents the attributes applied within the code base. You’ll learn about the role of .NET attributes later in this
chapter.
Understanding Reflection
In the .NET universe, reflection is the process of runtime type discovery. Using reflection services, you
are able to programmatically obtain the same metadata information displayed by ildasm.exe using a
friendly object model. For example, through reflection, you can obtain a list of all types contained within
a given *.dll or *.exe assembly, including the methods, fields, properties, and events defined by a given
type. You can also dynamically discover the set of interfaces supported by a given type, the parameters
of a method, and other related details (base classes, namespace information, manifest data, and so
forth).
560