Converting member variables to strings with using reflection from base class

kerdemdemir kerdemdemir at gmail.com
Fri Dec 22 21:13:31 UTC 2017


I want to make a logging function for member variables by using 
reflection.

import std.stdio;

class D : B
{
     override void foo() {
         a  = 4.0;
         b  = 3.0;
     }
     double a;
     double b;
}

class B
{
     void Log()
     {
         auto a = [__traits(derivedMembers, D)];
         foreach(memberName; a) {
             // Somehow write only member variables with their 
names
             // Result should be : a = 4.0, b = 3.0
         }
     }

     void foo()
     {
     }
}

void main()
{
      auto b = new D;
      b.Log();
}

As I wrote in the comments I want to see member variable's name 
and its value.
What is the best way to achieve that?

Erdem


More information about the Digitalmars-d-learn mailing list