getRtti

Registers and returns the Rtti for the type (or the variable) passed as argument.

  1. const(Rtti)* getRtti(const(char)[] typeString)
  2. const(Rtti)* getRtti(auto ref B b)
    const(Rtti)*
    getRtti
    (
    A = void
    B...
    )
    (
    auto ref B b
    )
    if (
    B.length < 2
    )

Examples

1 enum Option: ubyte {o1 = 2, o2, o3}
2 Option option1, option2;
3 // first call will register
4 const(Rtti)* rtti1 = getRtti(option1);
5 const(Rtti)* rtti2 = getRtti(option2);
6 // variables of same type point to the same info.
7 assert(rtti1 is rtti2);
8 // get the Rtti without the static type.
9 const(Rtti)* rtti3 = getRtti("Option");
10 assert(rtti3 is rtti1);
11 assert(rtti3.enumInfo.identifier == "Option");
12 assert(rtti3.enumInfo.members == ["o1", "o2", "o3"]);
13 assert(rtti3.enumInfo.values == [2, 3, 4]);
14 
15 assert(rtti3.enumInfo.valueType is rtti1.enumInfo.valueType);
16 assert(rtti3.enumInfo.valueType is rtti2.enumInfo.valueType);
17 assert(rtti3.enumInfo.valueType is getRtti!ubyte);

Meta