Book a Demo

Author Topic: Duplicate attribute when CamelCasing  (Read 5682 times)

mrpmorris

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Duplicate attribute when CamelCasing
« on: April 07, 2012, 07:33:53 am »
I have added a stereotype overload for the code template "attribute declaration" (as below.)  If I do not camel case the attribute name then on subsequent code generations EA notices I have an "ID" attribute already in the source file and doesn't add it again, however if I do camel case the attribute name then EA sees there is no "ID" (because it is "iD") and applies this template again.

How do I prevent that from happening?


%PI=""%
private
 %RESOLVE_QUALIFIED_TYPE(".", "int")%
 %CONVERT_NAME(attName, "Pascal Case", "Camel Case")%;\n
%CONVERT_SCOPE(attScope)%
 virtual
 %RESOLVE_QUALIFIED_TYPE(".", "int")%
 %attName%\n
{\n
      get { return %CONVERT_NAME(attName, "Pascal Case", "Camel Case")%; }\n
      private set { %CONVERT_NAME(attName, "Pascal Case", "Camel Case")% = value; }\n
}\n
%endTemplate%
« Last Edit: April 07, 2012, 07:34:56 am by mrpmorris »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Duplicate attribute when CamelCasing
« Reply #1 on: April 13, 2012, 08:36:20 am »
Essentially, don't change attribute names (or any other name) in code generation templates.

If you need to ensure particular naming conventions then you'll need to do it via a transformation.

mrpmorris

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Duplicate attribute when CamelCasing
« Reply #2 on: April 13, 2012, 04:42:04 pm »
Quote
Essentially, don't change attribute names (or any other name) in code generation templates.

If you need to ensure particular naming conventions then you'll need to do it via a transformation.

How is that done?  Ideally what I would like to be able to do is to add an attribute to my model, and depending on a tagged value "HasUserCode" do this

HasUserCode=False
public virtual string AttributeName { get; set; }

HasUserCode=True
private string attributeName;
public string AttributeName
{
  get { return attributeName; }
  set { attributeName = value; }
}

How would I achieve that?  My trial has nearly expired and I don't think there is any way I will be able to work it out in time.

Thanks
« Last Edit: April 13, 2012, 05:12:37 pm by mrpmorris »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller

mrpmorris

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Duplicate attribute when CamelCasing
« Reply #4 on: April 13, 2012, 05:14:41 pm »
Quote
See here:
http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/model_transformation/mdastyletransforms.html

Geert

Thanks Geert.  Hopefully I will be able to read that this weekend.  Hopefully it will describe how to "override" the existing C# template without having to copy it and do this kind of thing, will it?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Duplicate attribute when CamelCasing
« Reply #5 on: April 13, 2012, 05:25:38 pm »
Tranformations are different from code generation templates.
In a transformation you "transform" a model from one format to another (in MDA terms from say PIM to PSM).
The idea is that you have one UML model that you work on (PIM) and you then tranform that model into the different platform specific models (PSM)  that you need for you implementation.
That could be a database model, a C# model, a GUI model, ...
From those PSM you can then start code generation using templates.

The idea of a PSM is that is matches the target platform one-to-one. So each attribute, property, column, etc... is modeled as such in UML.

Geert

PS. If you nee more time to evaluate EA you can always send an email to [email protected]. They will probably give you an extension without a problem.