Can one pass state between aspects?

One can trivially pass arbitrary data between the aspect class and a template via the 'args' parameter. As Metalama cannot yet create class out of thin air, I need to modify the override method of another class to do different things based on the data captured (and fields created) on another class (where it's later going to reference this second class and do things with it). Question: Can I pass any data from the "parent" aspect into this "child" aspect at compile-time?
3 Replies
Whit
WhitOP2y ago
Given that either aspect needs to run against a separate class/type, it suggests that they're not quite the parent/child relationship described in the docs (https://doc.metalama.net/conceptual/aspects/child-aspects) since it says they can't be of different types, but is there any other way of accessing a dictionary of data in one aspect from another?
Gael Fraiteur
Gael Fraiteur2y ago
A "child" aspect in Metalama is by definition an aspect instantiated by a definition. You can pass state through the constructor. Otherwise, you have IAspectInstance.AspectState which you can use at your own will. So your child aspect, or any aspect, can ise IDeclaration.Enhancements().GetAspects().AspectState You should rather make your AspectState ther immutable or thread-safe. Can I close this post @xaniff or do you need more help? I noticed the documentation topic about child aspects is quite minimalistic.
Whit
WhitOP2y ago
Haha, I've rewritten my follow up question here umpteen times but I can't figure out what it is I'm trying to ask for Let's close this for now and I'll revisit once I get back to it. Currently blocked on another issue I put directly onto GitHub.
Want results from more Discord servers?
Add your server