Metalama Community

MC

Metalama Community

Join the community to ask questions about Metalama Community and get answers from other members.

Join
Andreu
Andreu7/11/2023

Can Metalama suppress compiler errors?

Hello! I want to know if I can use Metalama in my library. The users of my library have to declare the next class with this inheritance: public class EmailAlreadyExists(string email) : BusinessException("{0} already exists")...
Xaniff
Xaniff7/3/2023

Eligibility rule based on target method not returning void

Typically eligibility rules I've put together are based on a specifically typed return or paramters. I can't figured out how to do this so I thought I'd ask here - how can one add an eligibility rule that excludes methods that return a void? Thanks!
domsinclair
domsinclair6/23/2023

Follow up question from yesterday's meetup

Now that I've had time to review what was discussed I think I can now ask the question I'd wanted to more accurately than I could at the time. This question is specifically targeted at aspects that you might create that would target a wide variety of methods. An obvious example here is logging so we'll stick with that but logically the principle would apply yo any any all general purpose aspects. We can create a straightforward
LogAttribute : OverrideMethodAspect
LogAttribute : OverrideMethodAspect
and that aspect will be applied to different methods via the dynamic? OverrideMethod . ...
Xaniff
Xaniff6/18/2023

Please cache licensing key rather than check every build

Every time I attempt to build an aspect today, I'm getting an error that I've got an invalid license key and that I should get one from the Metalama website, which appears to be offline. I'd like to request that the local licensing scheme be updated to support say, a three-day cache or so. In the future, if the licensing server goes offline, at least it'll work over the weekend until your team is able to resolve the issue. Thanks!...
Xaniff
Xaniff6/16/2023

Documentation: Bad link

At https://doc.metalama.net/conceptual/using/fabrics there's a link at the bottom titled "Configuring aspects with fabrics" pointing to https://doc.metalama.net/conceptual/using/fabrics/configuring but clicking this results in a popup indicating it 404s (visiting it manually does the same and redirects to the search page).
Xaniff
Xaniff6/15/2023

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?...
domsinclair
domsinclair6/12/2023

Ordering Aspects

In the documentation it states: 'Aspects must be ordered using the AspectOrderAttribute assembly-level custom attribute. The order of the aspect classes in the attribute corresponds to their order of execution. using Metalama.Framework.Aspects; [assembly: AspectOrder( typeof(Aspect1), typeof(Aspect2), typeof(Aspect3))] '...
domsinclair
domsinclair6/12/2023

This error has me foxed

It's our old friend LAMA0001 Can't work out where it is getting Net Framework reference from....
domsinclair
domsinclair6/8/2023

AddAspect Refactoring

Consider the following scenario. There are two aspects that can potentially be added to a method (in this case it's logging but I think that it's actually immaterial). [LogMethod] logs a method. [TimedLogMethod] does exactly the same only adds timing as well. ...
domsinclair
domsinclair6/7/2023

RemoveAspectIfEligible?

Thinking out loud here. Title should actually be RemoveAspectIfPresent? Is there a case for having a RemoveAspectIfPresent<> function to add to Fabrics?...
domsinclair
domsinclair6/5/2023

Testing Fabrics

Short of actually creating a project that covers all of the bases that one would want to cover is there a way to test fabrics present in Metalama that I have somehow missed?
domsinclair
domsinclair6/2/2023

Eligibility MustNotHaveAspectOfType

I want to have intellisense show a red squiggle under and attribute if it is added to a method that already has another attribute added.
I had assumed that MustNotHaveAspectOfType would fit the bill here but it seems I'm mistaken. What should I be using? Whilst we're on that subject can that eligibility be chained in an upwards direction. So for example if I apply a [NoLog] attribute to the class can I add build eligibility to a method aspect that would pick that up.? DeclaringType seems not be an option when applied to builder in the BuildEligibility override....
domsinclair
domsinclair6/1/2023

Test should surely either both pass or both fail

Within the following repository (https://github.com/domsinclair/VtlSoftware.LoggingAspects) there are two tests on methods, one with and one without params. As far as I can see either both should pass or both should fail. It seems to be counter intuitive that one passes and the other fails, given the nature of the reported error.
domsinclair
domsinclair5/31/2023

Testing Issue

I've followed the basic instructions in the Documentation for testing Aspects (https://doc.metalama.net/conceptual/aspects/testing/aspect-testing) Starting off with something simple to hopefully make it easier. However I'm getting an Asert.Equal() failure. Could the fact that CodeRush can automatically add regions to code when it is saved be the cause of this?...
domsinclair
domsinclair5/31/2023

Has anyone tried the Ctrl + . refactor menu recently?

According to the documentation Invoking Ctrl + . to pull up the refactor menu should (if they are available in that context) offer you the option to add an aspect, I'm not seeing that in VS 2023 17.6.2
domsinclair
domsinclair5/30/2023

Is it possible to mix aspects that call different parts of a class (ie Methods and Properties)?

Pretty much as per the subject line. Consider the following scenario where one has aspects to log methods, Properties and eventually (subject to future metalama developments) Events. I would like to create fabric extension methods that would add all two / three at the same time....
domsinclair
domsinclair5/30/2023

Is this section of the documentation wrong?

I'm looking at the following topic (https://doc.metalama.net/conceptual/using/fabrics/adding-aspects) and in particular the second example, oddly enough because I want to establish the best way to add more than one aspect using a single fabric. Is it me or does the example not actually demonstrate what the section purports to cover?...
Xaniff
Xaniff5/30/2023

Why is it indicating I have compile-time code despite not?

See the screenshot - Is there some way to decorate this to make clear that nothing in the class contains compile-time only code?
No description
Xaniff
Xaniff5/28/2023

How do I invoke (and cast) an introduced generically typed field?

Bear with me - there's a lot going on here. Also Discord is funky about styling my code, so I'm handwriting it (pardon any typos). At a high level, let me explain where I'm trying to go and then I'll get into the issue. I want to attach an attribute to a target type that defines a type (TEntity) and another type (TEntityId) so I can use these to introduce some advice later on. I can retrieve those no problem - each is saved as an INamedType on the BuildAspect method. I then want to iterate through most of the properties of the TEntity type itself and introduce at least one field for several of them, but the type of the field depends on the type of the property itself. Again, this is set up and works fine. I save all the references to the introductions in a dictionary keyed by a reproducible mechanism to link the properties with the introduced types. Again, this works fine. My target type implements a base type which has a bunch of event callbacks in place. What I want to do is replace the last methods in those event callback chains with a method that can do operations against some or all of these introduced fields and this is where I'm having some difficulty....
Xaniff
Xaniff5/27/2023

Integration with VS to display introduced elements in partial classes

I can use compile-time generated elements from my run-time code by marking a class as partial, but I still get all sorts of disconcerting red squigglies when I do so and don't get to benefit from any Intellisense regarding the types of anything I introduce. I don't know to what degree you have control over this, but it'd be amazing to be able to attach an aspect to a class, mark the class as partial and then utilize the introduced members as though they were part of the code I'm typing right there. Take this first screenshot example where the _elements field is introduced by the InsertProperty aspect typed according to the type passed into the TargetType attribute. It works and when running the program I get the line added there, but t's not clear from eyeballing the class that this would work without explicitly trying it. Getting the visual confirmation that the IDE thinks it should work right without it citing all these errors (screenshot #2) would be a huge help....
No description