Suppose I want an object with a list of strings and every method that this object gets passed to adds its name to the list of strings. Basically it's a stack trace, except unlike a stack trace it keeps a record of everywhere it's previously been.
In order to do this, I would have to put code in every method it goes through to add itself but if it went through methods that didn't know to add themselves then of course it wouldn't have a record of having been through those methods.
It would be cool if it were possible to make an object self aware, so to speak, of the methods it goes through but I don't think it is. But I'm wondering if there is any other way to get a record of all methods the object goes through, including those methods that don't know to update the object?
EDIT: Currently, I'm thinking the closest you could come to solving this would be to make any property/method that's accessed on the object update itself at that point in time. of course this wouldn't catch places that it simply passes through without being accessed.
Aucun commentaire:
Enregistrer un commentaire