Usability of "allMembers and derivedMembers traits now only return visible symbols"
Ethan Watson via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 31 01:33:28 PDT 2016
On Wednesday, 31 August 2016 at 08:06:05 UTC, Basile B. wrote:
> allow them to see everything, then use "getProtection" if you
> wanna be conform with the protection attributes.
That's how it used to work, but getProtection would fail if the
symbol wasn't public. Which led to me using a workaround to
something of this effect:
enum PrivacyLevel : string
{
Public = "public",
Private = "private",
Protected = "protected",
Export = "export",
Package = "package",
Inaccessible = "inaccessible"
};
//----------------------------------------------------------------------------
template PrivacyOf( alias symbol )
{
static if( __traits( compiles, __traits( getProtection, symbol )
) )
{
enum PrivacyOf = cast(PrivacyLevel) __traits( getProtection,
symbol );
}
else
{
enum PrivacyOf = PrivacyLevel.Inaccessible;
}
}
//----------------------------------------------------------------------------
Still not an ideal solution - because if I'm trying to serialise
and deserialise everything in between module reloads I still need
to do the .tupleof method to get all data members; and if I want
to define privacy levels for functions I'm automatically binding
from C++ I need to muddy those waters with UDAs etc.
More information about the Digitalmars-d
mailing list