Book a Demo

Author Topic: CodeGen: Prevent Finalizer in C#I  (Read 4387 times)

eAndy

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
CodeGen: Prevent Finalizer in C#I
« on: March 24, 2007, 04:20:52 am »
Generating code in C#.

I always get a destructor/finalizer when generating C# code.

Drives me nuts. Has always worked this way.

Typically I have to mod the code template to exclude it.

This time I want an answer if any one has one.

In the code template I see this

%if genOptGenDestructor == "T" and classHasDestructor != "T" and classHasFinalizer != "T"%

I believe the getOptGenDestructor is the setting in the Tools-Options-ObjectLifetime

Where are the classHasDestructor and classHasFinalizer.

I'm guessing they're on the class but I'm certainly missing something.
« Last Edit: March 24, 2007, 05:10:14 am by eAndy »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: CodeGen: Prevent Finalizer in C#I
« Reply #1 on: March 25, 2007, 01:13:31 pm »
classHasDestructor and classHasFinalizer return "T" if the current class has a method matching the pattern expected for a destructor or finalizer respectively.  You can't modify their results without adding a destructor or finalizer to your class.

If you've turned off the option to generate a destructor in Tools | Options | Object Lifetime, then a destructor won't be generated.  You'll also want to turn off Tools | Options | C# | Generate Finalizer.  There is also Generate Dispose on the same page.

eAndy

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: CodeGen: Prevent Finalizer in C#I
« Reply #2 on: March 27, 2007, 01:26:41 pm »
have you tried this in C#?

I've turned off the option to generate a destructor in Tools | Options | Object Lifetime, and turned off Tools | Options | C# | Generate Finalizer and turned off the Generate Dispose on the same page.

Generate code.... Whoop! there it is! A dirty no good down low nasty old destructor/finalizer.

Any other ideas?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: CodeGen: Prevent Finalizer in C#I
« Reply #3 on: March 27, 2007, 02:37:06 pm »
Quote
have you tried this in C#?

Not immediately before replying to your question, but I have done it MANY times.

Quote
Any other ideas?

I suspect that the option is set on the class itself.  To check what options are set, open the Code Generation dialog (Select single class, press Ctrl+G) and press the advanced button.

To clear the options for all of your classes so that they use the model options have a look at http://www.sparxsystems.com.au/EAUserGuide/index.html?resetoptions.htm.

eAndy

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: CodeGen: Prevent Finalizer in C#I
« Reply #4 on: March 27, 2007, 06:16:59 pm »
That was it.

There's an advanced button on the Code Generation window.

If you go into "code lifetimes" its a duplicate of the Tools - Options - code lifetimes but they're disconnected and not saving the data in the same place.

I'd say dumb only b/c I haven't found a good use for it yet and its been very frustrating finding it.

I'm certain there will be a day when I'm singing its praises and calling the designers genius.

Thanks

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
RESOLVED: CodeGen: Prevent Finalizer in C#I
« Reply #5 on: March 28, 2007, 01:52:09 am »
Quote
genius.


???  Eeevil geneii  ???

hth
Lets start using the subject line on posts more constructively.

Andy has done "A good thing" by posting a comment that his issue wa resolved.  I'm just suggesting that it would be nice to see that "outcome" reflected in the subject line.

On the same but a different line.  IF the "discoverer's" of spam could a) add a "SPAM: xxx" to the subject of their spam replies, and b) somehow notify whoever it is at Sparx that is doing the excellent job of de-spamming that "here's another one!", I'm sure we could all get back to whatever normality is in <insert your local galaxy here>.

Coments? Comets? Comments?


bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.