Book a Demo

Author Topic: treatment of c# properties in code generation  (Read 3255 times)

roates

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
  • It is not that hard
    • View Profile
treatment of c# properties in code generation
« on: June 06, 2005, 12:58:03 am »
Hi. Please follow along for the question...

1.

Create a simple c# class and then reverse engineer it into EA 5.0:

here's the simple class:

using System;

namespace Man
{
  public class Man
  {
     int _Height;
     int _Weight;

     public Man()
     {
     }

     public int Height
     {
        get
        {
           return _Height;
        }
        set
        {
           _Height = value;
        }
     }

     public int Weight
     {
        get
        {
           return _Weight;
        }
        set
        {
           _Weight = value;
        }
     }
  }
}


2. Now, after reverse engineering it into EA 5.0, try to forward engineer it to a new file somewhere:

Here's the result:

///////////////////////////////////////////////////////////
//  Man.cs
//  Implementation of the Class Man
//  Generated by Enterprise Architect
//  Created on:      06-Jun-2005 5:33:22 PM
//  Original author: Russell Oates
///////////////////////////////////////////////////////////

namespace Man {
public class Man {

private int _Height;
private int _Weight;

~Man(){
}

public virtual void Dispose(){
}

public Man(){
}

public int Height{
get{
return <unknown>;
}
set{
<unknown> = value;
}
}

public int Weight{
get{
return <unknown>;
}
set{
<unknown> = value;
}
}

}//end Man

}//end namespace Man


How can I make EA that <unknown> is not the answer? I imagine quite a few users woul've come across this before...

Thanks,

Russell Oates

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: treatment of c# properties in code generation
« Reply #1 on: June 06, 2005, 04:34:00 pm »
The short answer is to set a tagged value "attribute_name" for each of the properties.

So, property height gets the tagged value "_Height".

The slightly more detailed response is that you can make the reverse engineering recognise that the properties match.  (Which currently isn't done because it doesn't look inside the body at all.)

What stopped EA from recognising it was the underscore before the name.  You can configure EA to look for something without the _ by adding it to the prefixes to remove when creating properties. (Tools | Options | Generation | Remove prefixes when generating Get/Set properties)

I've done this, reverse engineered your code and generated it out again.  It works correctly.

Simon

roates

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
  • It is not that hard
    • View Profile
Re: treatment of c# properties in code generation
« Reply #2 on: June 06, 2005, 05:29:30 pm »
Thanks for the quick reply simmonm.

After adding the underscore character to the set under "Remove prefixes when generating Get/Set properties" and then repeating the steps in the question (EA imports class, EA exports class) it worked.

Thanks again.

Russell Oates