O'Reilly logo

D Cookbook by Adam D. Ruppe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending the runtime type information

D's built-in TypeInfo doesn't provide nearly as much information as we can get from the compile-time reflection tools. Here, we'll create an extended type info with custom data.

How to do it…

Let's execute the following steps to extend the runtime type information:

  1. Create an interface with methods exposing the information you want to make available at runtime.
  2. If your method works with the data, remember that RTTI is typically used with very little compile-time type information. Thus, methods should take a generic runtime type, such as Object or void* in the generic interface.
  3. Create an associative array of your interface keyed on TypeInfo.
  4. Write helper functions to retrieve the information from the associative ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required