Chapter 8. Reflection

D supports limited runtime reflection out of the box as well as rich compile-time reflection that can be used in code generation efforts, custom semantic checks, building additional runtime reflection information, and more. In this chapter, we'll be covering the following recipes:

  • Getting dynamic runtime type information
  • Getting a list of child classes
  • Determining whether a module is available
  • Getting a list of all methods or fields in a module or an object
  • Inspecting function overloads
  • Determining names, types, and default values of function parameters
  • Getting components of complex types
  • Using user-defined attributes
  • Implementing a custom lint-style check for virtual functions
  • Extending the runtime type information
  • Creating a command-line function caller

Introduction

Reflection is commonly associated with virtual machines of interpreted languages, but D proves it can work well with a natively compiled language too. D provides some built-in runtime reflection, a lot of compile-time reflection, and ways to make the compile-time information available at runtime to bridge the gap while only paying for what you use.

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

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