Sunday, July 17, 2011

C# Code Generation on Sparx Enterprise Architect - Curly braces

C# code generation on Sparx EA will have the opening curly braces at the end of the line instead of a new line:

namespace CtrlAltDelete.Library.Helpers.Forms {

}

Instead of

namespace CtrlAltDelete.Library.Helpers.Forms 
{

}

To fix this, edit the C# code generation template:

1. press Ctrl+Shift+P

OR

1. Go to Settings menu
2.Code Generation Templates
3. On Language dropdown, select C#
4. On Namespace Body, line 14, replace "{" by "\n{"

\n{
%PI="\n\n"%
%list="Namespace" @separator="\n\n" @indent="\t"%
%list="Class" @separator="\n\n" @indent="\t"%
}//end namespace %packageName%

Click Save

5.On Class Body, line 8, replace "{\n" by "\n{\n"
\n{\n
%PI="\n\n"%
%list="InnerClass" @separator="\n\n" @indent="\t"%
%list="Attribute" @separator="\n" @indent="\t"%

Click Save

6. On Operation Body, line 6, replace "{\n" by "\n{\n"
\n{\n 
$wrap = %genOptWrapComment=="-1" ? "-1" : "40"%
$behavior = %WRAP_LINES(opBehavior, $wrap, "\t//", "")%

Click Save

7. On Operation Body -> Property (under Stereotype Overrides), line 35, replace "{" by "\n{"
\n{ 
$wrap = %genOptWrapComment=="-1" ? "-1" : "40"%
$behavior = %WRAP_LINES(opBehavior, $wrap, "\t//", "")%

That's it pancit!

No comments:

Post a Comment