Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: idof on February 06, 2006, 08:34:43 am

Title: How do I declare a static class ?
Post by: idof on February 06, 2006, 08:34:43 am
I'm adding a c# class and I want to mark it as static, so when it's generated, it will be generated with the word "static" in it's declaration.

Is there a way to specify for a class that it is static ?

Ido.
Title: Re: How do I declare a static class ?
Post by: Eve on February 06, 2006, 01:23:10 pm
Well, it's meant to be by adding a tagged value "static" = "true".  But the default code generation templates don't reflect that.

By the way.  The help now includes a section that describes the conventions used when modeling each language that EA supports.

See http://www.sparxsystems.com.au/EAUserGuide/index.html?csharp_conventions.htm

It doesn't answer this question, but it should be a bit better than my previous advice to see how EA reverse engineers something.
Title: Re: How do I declare a static class ?
Post by: idof on February 07, 2006, 01:28:43 am
Hi Simon.
As you said, the c# conventions is not very helpfull, but I did find the "tagged values" tab and created a new value called "static".

I'd appreciate if you can direct me to information about how to use tagged values in code generation templates (I have no problem changing the template myself, since I already added some lines there to support c# attributes)

Thanks,
Ido.
Title: Re: How do I declare a static class ?
Post by: Eve on February 07, 2006, 01:10:43 pm
Ok.  The information is in the help http://sparxsystems.com.au/EAUserGuide/index.html?taggedvaluemacros.htm.

My updated template is
Code: [Select]
$bases=%ClassInherits%
%if $bases != ""%
$bases=" "+$bases
%endIf%
$generic = %list="ClassParameter" @separator=","%
%if $generic != ""%
$generic = "<" + $generic + ">"
%endIf%
%if classTag:"Attribute" != ""%
%REPLACE(classTag:"Attribute", ";", "\n")%
%endIf%
%PI=" "%
%if elemType == "Interface"%
%classTag:"unsafe"=="true" ? "unsafe" : ""%
%CONVERT_SCOPE(classScope)%
%classTag:"new"=="true" ? "new" : ""%
%classTag:"partial"=="true" ? "partial"%
%PI=""%
interface %className%$generic$bases
%classTag:"genericConstraints" ? " " value%
%endTemplate%

%classTag:"unsafe"=="true" ? "unsafe" : ""%
%CONVERT_SCOPE(classScope)%
%classTag:"new"=="true" ? "new" : ""%
%classAbstract=="T" ? "abstract" : ""%
%classIsLeaf=="T" ? "sealed" : ""%
%classTag:"static"=="true" ? "static"%
%classTag:"partial"=="true" ? "partial"%
%PI=""%
class %className%$generic$bases
%classTag:"genericConstraints" ? " " value%
Title: Re: How do I declare a static class ?
Post by: idof on February 08, 2006, 12:43:33 am
Hi Simon,
Thanks for the sample.
I've taken it a bit further and declared the "static" tag value as boolean, and to make it work in the template I just upper-cased the T in "true"

Thanks,
Ido.
Title: Re: How do I declare a static class ?
Post by: Eve on February 09, 2006, 01:17:23 pm
Fair enough.

Although here I should point out that reverse engineering will write the value "true" and that the comparisons in the code templates are case insensitive.