Giving Aspects Metadata ?
I've only just started messing with MetaLama and going thru the documentation and videos but I was wondering if its possible to give an attribute extra metadata to send based on the place its invoked for example
but what if I wanted extra metadata such as stuff you get along with MEF plugins if you are familiar with that but something lets say a string to set a logging verbosity.
then when you give the attribute to the function you do something like
I dont know if something like this alrady exists and I just missed it in the docs or if this would be a feature request. Also currently on the free license if this is a premium feature 🙂
4 Replies
This feature is called "call-site aspects" and is currently unsupported. The closest way you can implement this is to use the .NET StackFrame class to capture the caller.
If I understand you correctly, the simplest way to do this is to add the data to the aspect class:
If you want to keep it on another attribute, you can, by reading the attribute from your aspect:
Oooh that's an interesting idea, i didn't even think about adding the properties straight into the aspect I'll mess around with that, thanks.
I do this in an aspect I've written. Remember that the aspects themselves don't really exist at runtime - they're only a compile-time thing, so any metadata you're passing around about anything is only valid (unless you persist it somewhere) while it's building your project.
Because I do an analysis of how the properties are used and then inject all manner of things based on that analysis, I just store a Dictionary<string, INamedType> that I pass around between methods in the aspect.