views:

429

answers:

1

Using Enterprise Architect (version 7.5), I'm trying to refine the code generation for C#. To make an attribute with an initial value that is a string generate properly, the only way I've been successful is with the code below. Does anyone know if a simpler way to do this? It currently seems a little bloated.

%if attType=="string" and attInitial!=""%
 = "
%elseIf attInitial!=""%
 = 
%endIf%
%attInitial ? value%
%if attType=="string" and attInitial!=""%
"
%endIf%
+1  A: 
%if attInitial!=""% 
 =  
%attInitial% 
%endIf% 

EA's attInitial corresponds to Property.default in UML.

default : String [0..1]

A string that is evaluated to give a default value for the attribute when an object of the owning class is instantiated. -- UML 2.2 infrastructure 10.2.5, emphasis added

So according to UML, if the type of the property is string, then the value attInitial should be an expression which evaluates to a string, not the content of a string literal.

If you do want it to be a non-UML-complient extension string literal value, you have to write something a bit more complicated that what you have done above to handle escaping.

Pete Kirkham