MC
Metalama CommunityDrago-QCC
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 🙂
Gael Fraiteur•231d ago
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.
Petr Onderka•229d ago
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:
Drago-QCC•229d ago
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.
Xaniff•226d ago
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.
Want results from more Discord servers?
More PostsUnable to get aspect testing to workI've got a very simple class set up to apply a logging aspect to so I can get the hang down of testiHow to debug a "Cannot preview the transformed code: unknown error"?I've got an aspect that's building without error and a target project that's applying the aspect thaWarn on ineligibility instead of throwingI've got two conditions in my BuildEligibility for a method override aspect: If the target type is aReferencing value assigned to variable in statement builder within another statementGiven a statement that does something like:
```cs
var expr = new ExpressionBuilder();
expr.AppendVerSpecifying generic constraints of compile-time introduced typeI have a TypeAspect that has three attribute arguments when applied to a type. One of these is a `TyStep-through aspect-debuggingI'm sure I've asked this before, but I cannot find the thread in which it was answered (if I actuallCodeLens HelpMetalama is configured in CodeLens, and I have an aspect that has been applied. I am able to right-How to apply an attribute to a method introduced by another aspect?I have an aspect that has a dependency on another aspect. However, I'd like for downstream projects Advising the addition of code commentsUsing Metalama
Is there a way to advise adding code comments? For example, when I advise a method Set eligibility to not run against (built-in) methods of record classes or structsI've figured out how to set up an `If` statement for the record types, but I cannot figure out how tHow to specify an IMethod as the callback for an event?I'd like to specify an introduced method on a TypeAspect as the callback for an event handler.
1) WCreate NuGet with MetalamaWith source generators I have to add some MSBuild configuration, but with Metalama it seems I don't