Usability of "allMembers and derivedMembers traits now only return visible symbols"

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 4 02:06:58 PDT 2016


On Sunday, 4 September 2016 at 08:42:43 UTC, Martin Nowak wrote:
> On Sunday, 4 September 2016 at 07:24:42 UTC, Basile B. wrote:
>> The introspection creates a special structure for each 
>> property annotated with @Set, @Get, or @SetGet. This is a kind 
>> of interface for serialization/binding/object inspector (a bit 
>> like "published" in Object Pascal).
>
> But you can't access private fields outside of the current 
> module, so you need to mixin sth. to set/get the value anyhow.
>

But that's the point ! We are many willing to see this 
restriction removed for the traits because they are special., i.e 
they should allow to implement, using meta programming, features 
that less powerful languages do in intern. That's also why I 
propose to add a 3rd optional bool parameter to the allMembers 
trait:

enum RespectProtection = false;
enum IgnoreProtection = true;

__traits(allMembers, T, RespectProtection)
__traits(allMembers, T, IgnoreProtection)

The 3rd optional parameter, when not specified, would be set a 
default value of false (equivalent to __traits(allMembers, T, 
RespectProtection), to prevent breakage.

Because allMembers would act as a filter for getMember, 
getOverload...the protection check in getMember, getOverload... 
would be removed.

This will be obviously more complex than that but that's the idea.


More information about the Digitalmars-d mailing list