Serializer class

houdoux09 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 24 10:10:39 PST 2017


> I'm pretty sure you need to use "value.tupleof[i][0]" instead 
> of "mm[0]" as well.


it does not work but I found a solution, that's what I do :

abstract class BaseClass
{
     uint[] a = [9, 10, 5];
}

override class Test : BaseClass
{
    int t = 0;
    string s = "holla";
}

public static JSONValue Serialize(BaseClass value)
{
     foreach(member; __traits(allMembers, typeof(value)))
     {
        static if (__traits(compiles, 
to!string(__traits(getMember, value, member))))
        {
	  auto result =  __traits(getMember, value, member);
           static if(isArray!(typeof(value)) && !is(typeof(value) 
== string))
	  {
		// process	
	  }
	  else static if(is(typeof(value) == class) || is(typeof(value) 
== struct))
	  {
                // process	
           }
           else
           {
               // process	
           }
      }
}

void main(string[] args)
{
    Serialize(new Test());
}

The problem is that I can not retrieve the variables from the 
parent class.


More information about the Digitalmars-d-learn mailing list