Intent.Modules
Intent.Modules copied to clipboard
Intent Module Builder overrides my interfaces on my template class
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).
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
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.
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)
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.