Open extrawurst opened 8 years ago
ok i dug a bit deeper and found out __traits(derivedMembers..) and the like do not support accessing private fields, I had the same problem when i wanted to add private autowiring to the dependency injection framework poodinis. the solution as i found out using the irc is using T.tupleof. for reference the change in poodinis is here: https://github.com/Extrawurst/poodinis/commit/7d2ba1bef94aa569e28f8739ffa09fe0e0d42071
tupleof
doesn't work on classes though, the base classe's variables would be left out. There could be a static if
for structs but that could be messy. I'll take a look but I don't know if anything can be done.
A workaround is to mark the private member @NoCereal
and use postBlit
, or accept
to customize it and do it from the struct/class itself.
I just tried a little experiment with __traits(getAttributes)
and tupleof
and it doesn't seem to work. So using it would mean a lot of the functionality that cerealed provides would stop working.
we had the same problem with the base classes in poodinis and it can be solved iterating over the base classes also at ct: https://github.com/mbierlee/poodinis/commit/f84b0251100f1a8d84c3e31650e710e24ab07166
i am pretty sure what needs to be done can be done using tupleof and getAttributes, we do the same in poodinis: https://github.com/mbierlee/poodinis/blob/master/source/poodinis/autowire.d#L124
or what is it exactly with __traits(getAttributes)
that does not work with tupleof
?
Ah, I see. Your example does it correctly by using T.tupleof[i]
to get the attributes, I used the value instead of a type, which is why it didn't work. Makes sense.
Well, then it seems to be possible, but incredibly annoying and a lot work to do. Given that there's a workaround and I'm not terribly interested in supporting private fields, I'd be more than happy to accept patches, but I don't think I'll work on this myself.
Is it possible to serialize private fields of classes and structs ?