Closed jpseini closed 1 year ago
Hi @jpseini,
It's the latter, the current model is that the module/template authors needs to decide for themselves how to call the CSharpFileBuilder for a particular element type from Intent.
Are you just looking for an example, or do you find yourself having to make a lot of different templates to generate domain classes?
Thanks @JonathanLydall
Neither of those options - with all the configuration/design which can be done in the Domain Designer, I was just "concerned" that I might end up missing some translation between the two. But its not an issue, I'll just make sure to cater for all possible configuration in the translation.
@JonathanLydall - do you have an example of "converting" a ClassModel to a CSharpFile? Just so I can make sure I'm on the right track and doing it correctly?
Hi @jpseini,
Here's a quick example:
CSharpFile = new CSharpFile(this.GetNamespace(), this.GetFolderPath())
.AddClass($"{Model.Name}", @class =>
{
foreach (var attr in Model.Attributes)
{
@class.AddProperty(GetTypeName(attr), attr.Name.ToPascalCase());
}
foreach (var associations in Model.AssociatedClasses)
{
@class.AddProperty(GetTypeName(associations), associations.Name.ToPascalCase());
}
foreach (var operation in Model.Operations)
{
@class.AddMethod(GetTypeName(operation), operation.Name.ToPascalCase(), method =>
{
foreach (var parameter in operation.Parameters)
{
method.AddParameter(GetTypeName(parameter), parameter.Name.ToCamelCase());
}
});
}
});
If the model is as follows:
This would output the following code:
Does this give you what you are looking for?
Perfect - thanks @JonathanLydall and @garethbaars (apologies)
Ask a question
Is there existing functionality in any Intent modules, which is able to take a ClassModel instance (designed in the Domain Designer), and automatically convert it to a CSharpFile (the same as if it was generated using the builder pattern)? Or is the way to do that conversion up to the builder of the module (me in this instance) to do that mapping and setup of the class using the builder pattern to create an instance of CSharpFile?