IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

Modification of templates that are not implementing ICSharpFileBuilder #92

Open IvanSimanenka opened 3 weeks ago

IvanSimanenka commented 3 weeks ago

Ask a question

I'm trying to create a module, which would add ExcludeFromCodeCoverage attribute to all parts of the code that are fully managed by Intent Architect (classes, methods, constructors). So far I was able to fetch all templates which implement ICSharpFileBuilder interface and adjust them in the Factory Extension. However I still see some files are not processed. During investigation I found out that some templates (for example Intent.Application.FluentValidation.Dtos.ValidationService) do not implement ICSharpFileBuilder and are created using a different technology. This prevents me from doing any modifications to them (both in the scope of my task and for any possible future use cases).

JonathanLydall commented 3 weeks ago

Hi @IvanSimanenka,

Thank you for logging this issue, we have a solution in mind which we feel will work very well for this problem.

In general, we feel the strategy of trying to solve this by using the C# File Builder from a factory extension will probably have several challenges, including the one you just mentioned where some templates may not be using the C# File Builder as well as others, like having to implement DefaultIntentManaged logic.

However, (as it's fundamental to how it works) our RoslynWeaver is already aware of what code is fully managed and what is not. What we're going to do is add an extension point to our RoslynWeaver where one could register a visitor for it.

The visitor would have methods which can be override for different syntax node types (e.g. fields, method, classes, etc), each override would have a parameter with context containing data like which template it is for, the code management modes (at a granular level), existing file content, previous content, etc.

And finally, one would have the ability to alter the syntax node in whatever way you choose before the method returns, for example you could add an attribute. We would provide a working example for you here on exactly how to do this.

We don't expect it to be difficult for us to build at all and will be looking at this from our side as soon as possible. We'll post here once we have something you can try.