samedi 24 novembre 2018

Does D have relection?

Does D have reflection or anything close to it, to be able to access objects at runtime ?

if not :

How exactly would I access or edit objects at runtime ?

for example :

bool myFunc(string status){
    switch(status){
        case "create":
            Object my_obj = new createObject();
            write("Object has been created or whatever");
        break;

        case "mutate":
            //Don't want to have to make a global declaration
            my_obj.attribute = "A meme";
            write("Object has been mutated or whatever");
        break;

        case "delete":
            //Don't want to have to make a global declaration
            delete();
            write("Object has been deleted or whatever");
        break;

        default:
        //blah
        break;
    }


    return true;
}



void main(){
while(true)
{String status = readln();myFunc(status);}



}

This is all I can think of at the moment, please let me know what I misunderstand about D in regards to this topic.

I've looked through the documentation on dlang.org and couldn't really find something to do with reflection, or at least not in the way that Java has.

ps, the above code is pseudo-code which I just made up on the spot, I'm sure for whatever reasons it would not actually compile, I'm just hoping to get through that I want access to objects in a specific way just so it convenient for me.





Aucun commentaire:

Enregistrer un commentaire