Find, Execute, and Create Types at Runtime Using Reflection

The .NET Framework contains not just code but metadata as well. Metadata is data about assemblies, types, methods, properties, and so on used in a program. These assemblies, properties, types, and methods are classes defined within the C# programming language. These classes, types, and methods are retrieved at runtime to parse a developer's application logic for execution. Attributes allow us to add extra information to these programs as well as methods that can be used during runtime while executing application logic.

The .NET Framework also allows developers to define this metadata information during development. It can be read during runtime using reflection. Reflection enables us to create an instance of the type retrieved and to invoke its methods and properties.

In this chapter, we will understand how the .NET Framework allows us to read and create metadata, and we will also learn how to use reflection to read metadata and process it during runtime. In the Attributes section, we will focus on using attributes, creating custom attributes, and learn how to retrieve attribute information at runtime. The Reflection section supplies an overview of how we can use reflection to create types, access properties, and invoke methods. Reflection also allows us to retrieve attribute information; for example, this could be extra information that we provided to .NET Runtime to be processed while executing the application logic.

In this chapter, we will look at the following topics:

  • Attributes
  • Reflection

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.70