Curly braces and C# Code generation using Sparx Systems' Enterprise Architect
When I write code I like the curly braces to be on the next line
public class Customer
{
}
I use Enterprise Architect by Sparx Systems to create my UML. Unfortunately, the code generated looks like this
public class Customer{
}
There is no option to change this behavior in EA. To get this to happen in EA you need to modify the code generation template for C#. Go to Settings, Code Generation Templates and select C#. Using the code below update the EA templates for the sections in the headers with ======== underneath. For properties the item you need to select Operation Body and then in the list box below the main list box select Property. Remember to click save for each section that you modify. If you don't like the changes you can click the Get Defaukt Template button for each section.
Namespace Body
===============
$COMMENT="WARNING: THIS IS AN ADVANCED TEMPLATE"
$COMMENT="DO NOT MODIFY UNLESS YOU ARE AN"
$COMMENT="ADVANCED USER!"
%if packageHasGenClasses != "T"%
%list="Namespace" @separator="\n\n" @indent=""%
%endTemplate%
%if packagePath == "" or genOptCSGenNamespace != "T"%
%PI="\n\n"%
%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n\n" @indent=""%
%endTemplate%
\n{
%PI="\n\n"%
%list="Namespace" @separator="\n\n" @indent="\t"%
%list="Class" @separator="\n\n" @indent="\t"%
}//end namespace %packageName%
Class Body
==========
%if elemType == "Interface"%
{\n
%list="Operation" @separator="\n\n" @indent="\t"%
%PI=""%
}//end %className%
%endTemplate%
\n{\n
%PI="\n\n"%
%list="InnerClass" @separator="\n\n" @indent="\t"%
%list="Attribute" @separator="\n" @indent="\t"%
$ops=""
%if genOptGenConstructor == "T" and classHasConstructor != "T"%
$ops+="\tpublic "+%className%+"()\n\t{\n\n\t}"
%endIf%
%if genOptGenDestructor == "T" and classHasDestructor != "T" and classHasFinalizer != "T"%
$ops+="\n\n\t~"+%className%+"()\n\t{\n\n\t}"
%endIf%
%if genOptCSGenDispose == "T" and classHasDispose != "T"%
$ops+="\n\n\tpublic "
$ops+=%classHasParent=="T" ? "override " : "virtual "%
$ops+="void Dispose()\n{\n\n\t}"
%endIf%
%if genOptCSGenFinalizer == "T" and genOptGenDestructor != "T" and classHasFinalizer != "T" and classHasDestructor != "T"%
$ops+="\n\n\tprotected "
$ops+=%classHasParent=="T" ? "override " : "virtual "%
$ops+="void Finalize()\n{\n"
$ops+=%classHasParent=="T" ? "\t\tbase.Finalize();" : ""% + "\n\t}"
%endIf%
%if genOptGenCopyConstructor == "T" and classHasCopyConstructor != "T"%
$ops+="\n\n\tpublic "
$ops+=%className%+"("+%className%+" the"+%className%+")\n\n{\n\n\t}"
%endIf%
$ops
%list="Operation" @separator="\n\n" @indent="\t"%
}//end %className%
Operation Body
==============
%if elemType == "Interface" or opTag:"delegate" == "true" or opAbstract == "T" or opTag:"extern" == "true"%
%PI=""%
;
%endTemplate%
{\n
$wrap = %genOptWrapComment=="-1" ? "-1" : "40"%
$behavior = %WRAP_LINES(opBehavior, $wrap, "\t//", "")%
%if $behavior != ""%
$behavior\n\n
%endIf%
$destName = "~" + %className%
%if opCode != ""%
%WRAP_LINES(opCode, "-1", "\t", "")%
%elseIf opName == className or opName == $destName%
%elseIf opReturnType == "byte" or opReturnType == "char" or opReturnType == "decimal" or opReturnType == "double" or opReturnType == "float" or opReturnType == "int" or opReturnType == "long" or opReturnType == "sbyte" or opReturnType == "short" or opReturnType == "uint" or opReturnType == "ulong" or opReturnType == "ushort"%
\treturn 0;
%elseIf opReturnType == "bool"%
\treturn false;
%elseIf opReturnType == "string"%
\treturn "";
%elseIf opReturnType != "void" and opReturnType != ""%
\treturn null;
%endIf%
}
Operation Body : Property
=========================
%if elemType == "Interface" or opAbstract == "T"%
$att=%opTag:"attribute_name"=="" ? "<unknown>" : value%
%if opTag:"writeonly" == ""%
$read="\tget;"
%endIf%
%if opTag:"readonly" == ""%
$write="\tset;"
%endIf%
{
$wrap = %genOptWrapComment=="-1" ? "-1" : "40"%
$behavior = %WRAP_LINES(opBehavior, $wrap, "\t//", "")%
%if $behavior != ""%
$behavior\n
%endIf%
$code = %WRAP_LINES(opCode, "-1", "\t", "")%
%if $code != ""%
$code
%else%
$read
$write
%endIf%
}
%endTemplate%
$att=%opTag:"attribute_name"=="" ? "<unknown>" : value%
%if opTag:"writeonly" == ""%
$read="\tget\n\t{\n\t\treturn " + $att + ";\n\t}"
%endIf%
%if opTag:"readonly" == ""%
$write="\tset\n\t{\n\t\t" + $att + " = value;\n\t}"
%endIf%
\n{
$wrap = %genOptWrapComment=="-1" ? "-1" : "40"%
$behavior = %WRAP_LINES(opBehavior, $wrap, "\t//", "")%
%if $behavior != ""%
$behavior\n
%endIf%
$code = %WRAP_LINES(opCode, "-1", "\t", "")%
%if $code != ""%
$code
%else%
$read
$write
%endIf%
}