Book a Demo

Author Topic: How do I declare a static class ?  (Read 3934 times)

idof

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
How do I declare a static class ?
« 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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8104
  • Karma: +118/-20
    • View Profile
Re: How do I declare a static class ?
« Reply #1 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.

idof

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: How do I declare a static class ?
« Reply #2 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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8104
  • Karma: +118/-20
    • View Profile
Re: How do I declare a static class ?
« Reply #3 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%

idof

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: How do I declare a static class ?
« Reply #4 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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8104
  • Karma: +118/-20
    • View Profile
Re: How do I declare a static class ?
« Reply #5 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.