Learn how to use Reflection to obtain information about loaded CLR assemblies and the types defined within them, such as classes, interfaces, and value types.
- [Ted] One of the features that makes the .NET platform such a compelling platform for which to write code is we have this facility that allows us to access objects at runtime without knowing about them ahead of time. This is a facility that allows us to be able to do things like Entity Framework to be able to slurp data out of a relational database and drop it inside your object model, or serialization to take your objects and turn them into a byte array, such that they can be shipped across the network and invoked on other machines. The underlying facility driving all of this is a library called Reflection inside of the .NET environment.
And in this course we're going to talk about .NET Reflection and how to use it for your own programs. My name is Ted Neward, and I've been working with .NET since before it shipped back in 2001. And I am going to lead you through the path of Reflection, looking first of all at how to access that metadata at runtime and make it available to you so that you can examine these types at runtime. But then I'm also going to show you how we can use Reflection to manipulate those objects, to in fact construct objects that you don't have direct references to, to invoke methods and properties on those objects, and even to access the fields inside of those objects.
It's going to be an interesting ride, so buckle in, fire up Visual Studio, and let's get started.
- Working with the IL Disassembler (Ildasm)
- Namespaces and types
- Type API
- Properties API
- MethodBase and MethodInfo API
- Constructors API
- Fields API
- Constructing objects
- Accessing properties and fields
- Invoking methods