March 20, 2019
Hi,

What is the best way to write a class proxy ?
I need to intercept attribute access.

Example:

The user write a PODO:

class User
{
    string name;
}


Then he use my library:

auto user = mylib.get!User(); // return a proxy here

writeln(user.name); // intercept user.name access (how to do this ?)


March 20, 2019
On Wednesday, 20 March 2019 at 08:16:22 UTC, boolangery wrote:
> Hi,
>
> What is the best way to write a class proxy ?
> I need to intercept attribute access.
>
> Example:
>
> The user write a PODO:
>
> class User
> {
>     string name;
> }
>
>
> Then he use my library:
>
> auto user = mylib.get!User(); // return a proxy here
>
> writeln(user.name); // intercept user.name access (how to do this ?)

This is by far not unique and depends on features of the proxy, even if you restrict the user to PODOs... Besides this, for example:

´´´
module mylib;

auto get(T)()
{
    return new Proxy!T();
}

private class Proxy(T)
{
    T podo;
    alias podo this;

    this()
    {
        podo = new T();
    }
}
´´´