Book a Demo

Author Topic: C# properties code gen template  (Read 2389 times)

royd

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
C# properties code gen template
« on: August 31, 2005, 03:49:51 am »
Currently the C# code gen templates create properties with K&R style curly braces...

public string Code{
   get{
       return code;
   }
   set{
       code = value;
   }
}

however our standard is curly braces on a new line...

public string Code
{
   get
   {
       return code;
   }
   set
   {
       code = value;
   }
}

I've tweaked the last part of the Attribute Declaration template like this...

%if attStereotype == "property"%
\n{\n\t//read property\n\tget\n{;}\n\t//write property\n\tset\n{;}\n}
%endTemplate%;

which looked to be the place to make the chage and just puts in the appropriate newlines in and similar tweaks have worked ok for class declarations etc. However the curly braces are still inline i.e. the change is not picked up. Can anyone help? the code template docs are a little lite and it should be such a simple thing to achive.
I did wonder if the test is correct i.e. %if attStereotype == "property"% as the stereotype is actually on the operation not the attribute, however that just a guess and I've not got anywhere by tweaking the operation template accordingly.
Hope someone can help,
Royd.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# properties code gen template
« Reply #1 on: August 31, 2005, 03:48:52 pm »
You're right about that template not being where you want to be.  Look at the operation templates, you'll need to remove the %PI=""% line from the Operation template and add \n\t between get/set and { in the Operation Body stereotype override for property. (And probably also for indexer and event)

Simon

royd

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: C# properties code gen template
« Reply #2 on: September 01, 2005, 04:08:56 am »
Thanks for that,
I thought I may be missing something, I'd not looked at the overrides.
Royd.