domsinclair
domsinclair
MCMetalama Community
Created by domsinclair on 6/23/2023 in #technical-questions
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 .
We could though create specicific implementations for different method types like async using alternative templates that use OverrideAsyncMethod() or OverrideEnumerableMethod() to name but two. With that said here come the questions. Would it actually be best practice in such situations to create templates for all the possibilities one is likely to encounter? One would obviously have to determine which template is applied and when, which presumably would be done via the override of BuildAspect. Am I correct in my thinking here?
5 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
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))] ' From that I read this as meaning that Aspect1 will be executed, after which Aspect 2 will be executed after which Aspect 3 will be executed. This is the Log output from a sample I have built, reversing the execution of the Aspects: The bit that is of interest is at the bottom of both logs, which, to me at least makes no sense if the statement in the docs is accurate.
6 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
This error has me foxed
It's our old friend LAMA0001 Can't work out where it is getting Net Framework reference from. Project is on github https://github.com/domsinclair/VtlSoftware.MultiAspectSolution
4 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
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. Now consider the following method.
c#
private double Add(double a, double b) => a + b;
c#
private double Add(double a, double b) => a + b;
The LogMethodAttribute has the following BuildAspect and BuildEligibility options.
c#
public override void BuildAspect(IAspectBuilder<IMethod> builder)
{
if(!(builder.Target.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any() ||
builder.Target.Attributes.OfAttributeType(typeof(TimedLogMethodAttribute)).Any() ||
builder.Target.DeclaringType.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any()))
{
builder.Advice.Override(builder.Target, nameof(this.OverrideMethod));
}
}


public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
{
base.BuildEligibility(builder);
builder.MustNotBeStatic();
builder.MustNotHaveAspectOfType(typeof(NoLogAttribute));
builder.MustNotHaveAspectOfType(typeof(TimedLogMethodAttribute));
}
c#
public override void BuildAspect(IAspectBuilder<IMethod> builder)
{
if(!(builder.Target.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any() ||
builder.Target.Attributes.OfAttributeType(typeof(TimedLogMethodAttribute)).Any() ||
builder.Target.DeclaringType.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any()))
{
builder.Advice.Override(builder.Target, nameof(this.OverrideMethod));
}
}


public override void BuildEligibility(IEligibilityBuilder<IMethod> builder)
{
base.BuildEligibility(builder);
builder.MustNotBeStatic();
builder.MustNotHaveAspectOfType(typeof(NoLogAttribute));
builder.MustNotHaveAspectOfType(typeof(TimedLogMethodAttribute));
}
First issue If I select the add method and call up the refactor AddAspect I would expect to be offered both, I'm not though just the TimedLogMethod is offered. If I comment out the builder.MustNotHaveAspectOfType(typeof(TimedLogMethodAttribute)); line then I get both offered. If I do this in the Editor (without commenting out the linne in the buildEligibility method)
c#

[TimedLogMethod]
[LogMethod]
private double Add(double a, double b) => a + b;
c#

[TimedLogMethod]
[LogMethod]
private double Add(double a, double b) => a + b;
I would expect, or thought I would get a red squiggle under [LogMethod] but I don't. I'm guessing my BuildEligibility Method is wrong but I can't work out why.
13 replies
MCMetalama Community
Created by domsinclair on 6/7/2023 in #technical-questions
RemoveAspectIfEligible?
Thinking out loud here. Title should actually be RemoveAspectIfPresent? Is there a case for having a RemoveAspectIfPresent<> function to add to Fabrics?
2 replies
MCMetalama Community
Created by domsinclair on 6/5/2023 in #technical-questions
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?
14 replies
MCMetalama Community
Created by domsinclair on 6/2/2023 in #technical-questions
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.
6 replies
MCMetalama Community
Created by domsinclair on 6/1/2023 in #technical-questions
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.
2 replies
MCMetalama Community
Created by domsinclair on 5/31/2023 in #technical-questions
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?
11 replies
MCMetalama Community
Created by domsinclair on 5/31/2023 in #technical-questions
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
8 replies
MCMetalama Community
Created by domsinclair on 5/30/2023 in #technical-questions
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.
20 replies
MCMetalama Community
Created by domsinclair on 5/30/2023 in #technical-questions
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?
4 replies
MCMetalama Community
Created by domsinclair on 5/25/2023 in #technical-questions
InterpolatedStringHandler
I'm experimenting with the InterpolatedStringHandler. The idea, in simple terms is to do away with the interpolatedStringBuilder that we see in the examples for logging and replace it with this. One should then be able to create a generic logging aspect that utilises MEL ILogger and in the calling app just log plain text , or substitute a structured logger like Serilog. It transpires that this requires Ststem.Runtime.CompilerServices.Unsafe. technically this is marked as being compatible with .NetStandard 2.0 which logically one ought to create the class library containing the aspect with for maximum compatibility. However it would appear that this is somewhat deceptive. If I base the class library on .net 6.0 this issue goes away. This begs the following esoteric question. Given that Metalama is is in many ways a 'Postsharp for the .net Core world' should we be assiduously trying to enforce as much backward compatibility as possible?
13 replies
MCMetalama Community
Created by domsinclair on 5/25/2023 in #technical-questions
Is there a new Vsix?
As it's not possible to add a comment in the releases section I've had to add this here.
According to the release notes the Vsix should no longer be marked as preview. However I've just downloaded form the Extensions gallery and it is still very clearly marked as a preview version. What I really wanted to know though was whether it should in reality be 2023.1.2?
3 replies
MCMetalama Community
Created by domsinclair on 5/23/2023 in #technical-questions
Latest Build but getting this error
No description
6 replies
MCMetalama Community
Created by domsinclair on 5/20/2023 in #technical-questions
Metalama apparently looking for .net471 in a .net6 project
No description
4 replies
MCMetalama Community
Created by domsinclair on 5/18/2023 in #technical-questions
VS 2022 V17.6 Issue with Show Metalama diff
Installed the latest version of Vs 2022 today. On the very first opening Show Metalama Diff worked but it has steadfastly refused to do so since. No error message, no warning just an endlessly cycling Dialog telling me to please wait while Metalama is transforming the file.
14 replies