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

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
C# Code Generation Questions
« on: December 04, 2004, 09:09:04 am »
I'm just starting to review the Code Generation template definition language.  If anyone out there has some input on whether any of the following are possible and what the approach should be, you would save me some hunting:

1) I'd like to generate regions around each of the C# constructs.  For example, around the field definitions I'd like:

Code: [Select]
#region fields

private string field1;
private string field2;

#endregion

Is this possible with the code templates?

2) I'd like the default C# bracket layout from VisualStudio, in other words:

Code: [Select]
public Employee()
{
}

Thanks in advance -

Jeff Odell

Hans

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
    • View Profile
Re: C# Code Generation Questions
« Reply #1 on: December 04, 2004, 10:33:39 am »
Use Configuration - Code Generation Templates which allows you to define and override the code output in a very simple macro language.

What nerves a bit is the obvious lack of a parser: the execution appears to have been wrapped in a try block with an empty catch: That way you'll never know of where and why an exception occurred.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: C# Code Generation Questions
« Reply #2 on: December 05, 2004, 05:00:17 pm »
Both of those are possible and not even very difficult.

1)  In the class body template where it has a list macro just put the region stuff on either side.  Eg.

Code: [Select]
#region fields\n
%list="Attribute" @separator="\n" @indent="\t"%
\n#endregion
 One provisor is that this may not always work perfectly for synchronisation.  New things synchronised in may not go in the right spot.  (Particuarly inner classes)

2) Remove the %PI=" "% from the class template.

Simon

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: C# Code Generation Questions
« Reply #3 on: December 05, 2004, 07:20:45 pm »
Thanks - I worked a bit with the templates tonight and made good progress.  I have a couple other template questions if you can stand them:

1) I want to group the properties separate from the other operations.  I found the Operation Declaration and Operation Body templates that generate properties differently.  What I would like to do is to generate the following in the Class Body:

Code: [Select]
\t#region methods\n
%list="Operation" @separator="\n\n" @indent="\t"%
\n\t#endregion\n\n

for everything BUT properties, then:

Code: [Select]
\t#region properties\n
%list="Operation" @separator="\n\n" @indent="\t"%
\n\t#endregion\n\n

for ONLY properties.  Is there a way to formulate the list statement, or perhaps surround it with something, it so only certain Operation stereotypes?

2) How do I export all my changes?  When I export, it seems to only export a template I added (one I deleted to boot) and not my changes.

Thanks in advance - jlo

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: C# Code Generation Questions
« Reply #4 on: December 06, 2004, 02:22:00 pm »
You can put conditions on lists.

Code: [Select]
\t#region methods\n
%list="Operation" @separator="\n\n" @indent="\t" opStereotype != "property"%
\n\t#endregion\n\n
\t#region properties\n
%list="Operation" @separator="\n\n" @indent="\t" opStereotype == "property"%
\n\t#endregion\n\n


Export with Tools | Export Reference Data | C#_Code_Template.