Accessing UDA of private field

Jacob Carlborg doob at me.com
Sun Jan 6 06:43:20 PST 2013


I'm trying to adapt my serialization library, Orange, to use the new 
UDA's. Currently I have one template, NonSerialized, that I want to 
transfer to an UDA. This template works like:

class Foo
{
     int a;
     int b;

     mixin NonSerialized!(b);
}

When serializing Foo "b" will not be serialized. What the template does 
is adding a static field to the class, like this:

class Foo
{
     int a;
     int b;

     static enum __nonSerialized = ["b"];
}

Which I then can extract and use to exclude the fields from serialization.

This works fine to transfer to an UDA except in one case. That is when 
the field is not public. Orange will serialize all fields, regardless of 
the protection they have. I accomplish this by using the "tupleof" 
property of the class.

The problem is that to access a UDA attached to a field I need to pass a 
symbol to the __traits(getAttributes). With "tupleof" I can get the 
name, type and value of a field but I cannot get a symbol.

__traits(getMember) can be used to get the symbol but that will only 
work for public fields.

Does anyone have another solution? I had really hoped I could use UDA's 
in Orange.

https://github.com/jacob-carlborg/orange

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list