
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
753
Chapter 13
CHAPTER 13
Reflection
13.0 Introduction
Reflection is the mechanism provided by the .NET Framework to allow you to
inspect how a program is constructed. Using reflection, you can obtain information
such as the name of an assembly and what other assemblies a given assembly
imports. You can even dynamically call methods on a type in a given assembly.
Reflection also allows you to create code dynamically and compile it to an in-memory
assembly or to build a symbol table of type entries in an assembly.
Reflection is a very powerful feature of the Framework and, as such, is guarded by
the runtime. The
ReflectionPermission must be granted to assemblies that are going
to access the protected or private members of a type. If you are going to access only
the public members of a public type, you will not need to be granted the
ReflectionPermission. Code Access Security has only two permission sets that give
all reflection access by default:
FullTrust and Everything. The LocalIntranet permis-
sion set allows for the
ReflectionEmit privilege that allows for emitting metadata and
creating assemblies or the
MemberAccess privilege for performing dynamic invocation
of methods on types in assemblies.
In this chapter, you will see how you can use reflection to dynamically invoke mem-
bers on types, ...