Book a Demo

Author Topic: Modifying AttributeDeclaration in code template  (Read 2925 times)

Aidyn

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Modifying AttributeDeclaration in code template
« on: March 05, 2010, 06:08:49 am »
I am trying to change the styling in generated C# code by modifying the AttributeDeclaration template. For example for class properties I want to change parenthesis, to change default style below

public string FirstName{
            get{
                  return _firstName;
            }
            set{
                  _firstName = value;
            }
      }
to my own style
public string FirstName{
            get
                             {
                  return _firstName;
            }
            set
                             {
                  _firstName = value;
            }
      }
How can I accomplish that?
My attempt to change default template

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

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

Doesn’t produce expected result.

How can I circumvert this problem

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Modifying AttributeDeclaration in code templat
« Reply #1 on: March 05, 2010, 11:37:41 am »
You want the Operation Body stereotype override for property.  Not the attribute declaration template.

Aidyn

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Modifying AttributeDeclaration in code templat
« Reply #2 on: March 06, 2010, 02:23:16 am »
Thanks for prompt response Simon. Could you please provide an example how to do it - any help is greatly appreciated!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Modifying AttributeDeclaration in code templat
« Reply #3 on: March 09, 2010, 08:33:55 am »
Have you tried changing
Code: [Select]
%if opTag:"writeonly" == ""%
$read="\tget{\n\t\treturn " + $att + ";\n\t}"
%endIf%
%if opTag:"readonly" == ""%
$write="\tset{\n\t\t" + $att + " = value;\n\t}"
%endIf%
to
Code: [Select]
%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%
?
« Last Edit: March 09, 2010, 08:34:16 am by simonm »