Intent.Modules icon indicating copy to clipboard operation
Intent.Modules copied to clipboard

Intent Module Builder overrides my interfaces on my template class

Open dandrejvv opened this issue 6 years ago • 4 comments

Using the new Intent Module builder, I wanted to add IDeclareUsings and IHasTemplateDependencies to my partial class template but on the next code generation run, Intent wanted to take it out. I understand that when Signature = Mode.Fully, Intent will override the signature of the class (which includes the interfaces that it inherits from) and we need that to be so, so I suppose that one might need to add options in the modeler to specify whether you want to override things (like what I wanted to do).

dandrejvv avatar Feb 14 '19 10:02 dandrejvv

If you change the Attirubte in to the output file, so that the Signature = Mode.Merge, it becomes addative, i.e. it will add in changes from the Template and you can add changes manually in the code

joelsteventurner avatar Feb 14 '19 12:02 joelsteventurner

Hi @joelsteventurner
Understood. But won't that cause me to make manual changes to the class? Like if the template type changed, then I would have to manually update the template class's base type myself.

dandrejvv avatar Feb 15 '19 08:02 dandrejvv

It all depends on the scenario, if for example you add a new interface to the template, it would add the interface to the outputted class. If you changed the base class of the template, it probably wouldn't change in the outputed class as this is not an additive change, it would assume you have manually changed the base class. (would need to look at the code to confirm this)

joelsteventurner avatar Feb 15 '19 09:02 joelsteventurner

Ok, I'll describe a scenario that might be common. I start off with a template which I think will take only one element, so it looks something like this:

[IntentManaged(Mode.Merge, Body = Mode.Merge, Signature = Mode.Full)]
public class MyTemplate : IntentRoslynProjectItemTemplateBase<IClass>

I realize that I want to override the Usings and specify Template Dependencies (and thus change the Mode to Merge).

[IntentManaged(Mode.Merge, Body = Mode.Merge, Signature = Mode.Merge)]
public class MyTemplate : IntentRoslynProjectItemTemplateBase<IClass>, IDeclareUsings, IHasTemplateDependencies

Later I realize that I actually wanted to change the model from a single-item to a list-item so that my template receives multiple items. But now Intent does this (see end of signature):

[IntentManaged(Mode.Merge, Body = Mode.Merge, Signature = Mode.Merge)]
public class MyTemplate : IntentRoslynProjectItemTemplateBase<IClass>, IDeclareUsings, IHasTemplateDependencies, IntentRoslynProjectItemTemplateBase<IList<IClass>>

I also think from a usability point of view it would be great to give options in a stereotype to add certain "attributes" to a template so that newcomers can see that you can override Usings and you need to be able to specify which templates your template is dependent on, etc.

dandrejvv avatar Feb 18 '19 12:02 dandrejvv