Book a Demo

Author Topic: More C# Code Generation Questions  (Read 3302 times)

johnp

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
More C# Code Generation Questions
« on: February 06, 2007, 03:22:16 am »
I want to generate #regions and, having read a previous post, have been able to do so successfully (:)) for properties and methods in the Class Body template like this:

[size=13]\t#region Properties
%list="Operation" @separator="\n\n" @indent="\t" opStereotype == "property"%
\t#endregion
\t#region Methods
%list="Operation" @separator="\n\n" @indent="\t" opStereotype != "property"%
\t#endregion[/size]


However, I would like to take the principle further to separate out constructors and split the methods into private and public. I tried the former like this, but it doesn't work (:() - any help please?

[size=13]$sName = %className%
\t#region Constructors
%list="Operation" @separator="\n\n" @indent="\t" opName == $sName%
\t#endregion[/size]


This looks a BUG to me - I have proved that $sName contains the name of my class, and, if I temporarily code the offending line as
%list="Operation" @separator="\n\n" @indent="\t" opName == "MyClass"%
then it works for that class! I don't get it.

PLEASE HELP!
« Last Edit: February 06, 2007, 05:55:01 am by johnp »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: More C# Code Generation Questions
« Reply #1 on: February 06, 2007, 06:20:33 am »
I don't know if this is a bug per se, or a limitation in how EA parses this kind of script. It seems like the failing line is using a variable substitution where the others are using a built-in value.

Long shot here: have you tried enclosing the variable name in quotes?
No, you can't have it!

johnp

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: More C# Code Generation Questions
« Reply #2 on: February 06, 2007, 06:55:14 am »
What, you mean like this:
%list="Operation" @separator="\n\n" @indent="\t" opName == "$sName"%
No, this has no effect - I assume this condition is for operations named "$sName" . . . !

Come on guys - surely someone has solved this one?
« Last Edit: February 06, 2007, 06:55:33 am by johnp »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: More C# Code Generation Questions
« Reply #3 on: February 06, 2007, 01:26:47 pm »
People have done that and more.  For example
Quote
...
$COMMENT="output constructor region only if there are constructors"
$constructors=%list="Operation" opName==className%
%if $constructors!=""%
#region Constructors
$ops=""
%if genOptGenConstructor == "T" and classHasConstructor != "T"%
$ops+="\tpublic "+%className%+"()\n{\n\n\t}"
%endIf%
$COMMENT="output constructors in public/protected/private order"
%list="Operation" @separator="\n\n" @indent="\t" opName==className and opScope=="Public"%
%list="Operation" @separator="\n\n" @indent="\t" opName==className and opScope=="Protected"%
%list="Operation" @separator="\n\n" @indent="\t" opName==className and opScope=="Private"%
#endregion  // Constructors
%endIf%
...

As for what you're doing wrong.  The condition on that list needs to be evaluatabled in a separate context to the current template and therefore can't include variables.

johnp

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: More C# Code Generation Questions
« Reply #4 on: February 07, 2007, 01:12:17 am »
Thanks Simon thats great. I still haven't got my head around the template syntax . . .

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: More C# Code Generation Questions
« Reply #5 on: February 07, 2007, 01:19:40 pm »
Quote
Thanks Simon thats great. I still haven't got my head around the template syntax . . .

Then read the documentation (http://www.sparxsystems.com/EAUserGuide/index.html?codetemplatesyntax.htm) and then ask questions.