Book a Demo

Author Topic: C# curly brace placement  (Read 5137 times)

Paul Speranza

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
C# curly brace placement
« on: September 14, 2008, 10:44:04 am »
Is there any way to make the curly braces in C# generated code to be place on the next line?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# curly brace placement
« Reply #1 on: September 14, 2008, 10:50:34 pm »
Yes, there are ways to do this, with a few limitations.

Look at Macro | PI in the EA help index. You will need to scroll down the page quite a way to see it. That's a good starting point. [The examples are quite limited, and don't really give an idea of what results. You will need to experiment.]

Please note that you will need to create a custom template to do this. There's plenty of information in the EA help, but here's a good tip for a first-timer: Remember that you have to start from a copy of a built-in template, to create your own custom template.

Check out the white papers and demonstrations on the Sparx Web site for some more information.

And search the forum - try several keyword combinations - for examples.

HTH, David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# curly brace placement
« Reply #2 on: September 15, 2008, 08:10:29 am »
David is right about modifying the templates.

But as far as a custom template goes, all you need to do is start modifying the existing templates.  Your changes will be used instead of the default templates, but you can always get the default templates back using 'Get Default'.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# curly brace placement
« Reply #3 on: September 15, 2008, 09:03:35 am »
Thanks Simon. Much simpler, and the recovery is easy if you need to revert.
No, you can't have it!

Paul Speranza

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: C# curly brace placement
« Reply #4 on: September 17, 2008, 10:54:49 am »
Ok, Thnaks to all. I figured it out. The code  for the different sections is below.


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%
}