Metalama Community

MC

Metalama Community

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

Join

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

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....

How might I list the properties of a generic type within an aspect?

I want to translate the properties of a generic type constraint of the base type implemented by my target type into fields on my target via an aspect, but I'm struggling to figure out how to keep everything in compile-land so Metalama is happy. I've tried the following:
var propertiesOnType = builder.Target.BaseType.TypeParameters[0].ToType().GetProperties();
var propertiesOnType = builder.Target.BaseType.TypeParameters[0].ToType().GetProperties();
...
No description

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?...

Live re-application and diff view updates of aspects on save

It's awfully convenient to enable Continuous Testing in Visual Studio. I turn it on and every time I save a file, Visual Studio kicks in to re-run any unit tests that apply to that particular bit of code and if I've got the test tooling panel open, I can see in near real-time whether I've broken anything. Today, when I start making changes to as aspect, that little golden bar shows up at the top of Visual Studio indicating that I'm making changes to the aspect and when I'm finished, I can click the "I'm done" button. The aspect will be re-applied everywhere applicable and after a brief pause (indicated by the processing of background tasks icon in the bottom left of Visual Studio) I can right click any of the targets it's applied to, select the "Show Metalama Diff" option from the context menu and voila, there's the target with the applied aspect. If I already have a diff open, I have to close it and re-open it from a target. All well and good for now, but I'd like to propose that this workflow be updated to reflect something more akin to the Continuous Testing functionality. I'd love to instead shift the workflow to the following:...

Clear cache between version updates

I'm not entirely sure what the underlying issue is, but every time I upgrade Metalama versions and try to look at a Metalama diff, I see the popup indicating it's applying the aspects with the indefinite progress bar... and it never finishes. The only approach that's solved this is to open up the %Temp%\Metalama\ directory and delete the folder in CompileTime matching the name of the project (presumably some sort of cache). Is it possible that when an upgrade is performed, Metalama could delete the old caches itself so I needn't upgrade, close all my VS instances, delete it and then finally get back to work?...

Latest Build but getting this error

Am seeing this after adding the latest release builds to vs 17 .6
No description

How to extract the type parameters from an attribute (not the aspect)?

If I'm seeking to extract the generic types applied to a class I've marked with an attribute, this is easily done with:
var genericType = builder.Target.TypeParameters[0];
var genericType = builder.Target.TypeParameters[0];
...

Metalama apparently looking for .net471 in a .net6 project

Bit of a new one this and not exactly sure why as yet: VS2022 17.6 Metalama preview 2023.1.1...
No description

Feedback: Documentation update

I'd like to propose a slight tweak to the documentation that would improve understanding for future me. At https://doc.metalama.net/api/metalama_framework_code_syntaxbuilders_statementfactory the Parse(String) method "indicates that the parsed string can be inserted into the run-time code using InsertStatement(IStatement)." I would recommend this be updated to include an example of where one might find the InsertStatement, as in: "using InsertStatement(IStatement) as in meta.InsertStatement(IStatement) as the linked documentation also doesn't mention that this method is available on meta. Only on the "related" link at the bottom of this subsequent page does it link to "Writing T# Templates" and then on "Generating run-time code" do we fine a note of "To add a statement to the generated code, use StatementBuilder to create the statement and then meta.InsertStatement from the template at the place where the statement should be inserted`. By including this note on the StatementFactory and StatementBuilder pages, it would make it easier to understand how it might be implemented (especially if in the docs generated and bundled with the package on NuGet)....

Unable to check for existence of unbound generic typed attribute on type

I'm looking to build out the behavior of a Blazor component based on the attributes applied to the type: ```cs public abstract record EditStartAction(); public sealed class CanEdit<TEditAction> : Attribute...

Limit reported Metalama exceptions in VS

For whatever reason today, I seem to be encountering an unusual number of exceptions reading "Metalama ran into an unexpected problem: Method not found: 'Metalama.Framework.Engine.Options.MSBuildProjectOptions Metlama.Framework.Engine.Options.MSBuildProjectOptionsFactory.GetProjectOptions(Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider, System.Nullable`1<System.Collections.Immutable.ImmutableArray12<System.Object>, Metalama.Compiler.TransformerOptions)'." I'll share the rest of the exception in the message below. My questions though - this is popping up an awful lot and obscuring the warning that indicates I'm editing the aspect with the "I'm done" option to refresh the compiled code. Absent ya'll simply fixing the underlying issue, it possible to 1) limit the number of exceptions shown and/or 2) could the "I'm done with the changes." be placed in a different location in the IDE, separate from the exceptions?...

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.