Author Topic: Reverse Engineering of C# Auto-Properties  (Read 2254 times)

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Reverse Engineering of C# Auto-Properties
« on: May 07, 2012, 11:53:56 pm »
I am working with Sparx tech support to try and get C# Auto-Implemented Properties to reverse engineer into associations when the return value is a class or collection of a class.  

Current, reverse engineering creates an operation (from a UML perspective) which is fine, and marks is with a stereotype of <property>.  What it does not do is create the association to the other class.  I've seen this question in the forum a couple times with no responses from either Sparx of the community.

From my email with support:


Since C# 3.0 (August 2007) the C# language has supported Auto-Implemented Properties.  

http://msdn.microsoft.com/en-us/library/bb384054.aspx

These properties that do not need a backing field defined for brevity in the language.  They are in widespread use - most code quality tools will flag your code if you have code where the property only gets and sets the field:

No:

        private List<Class6> _class6ListProp;

        public List<Class6> Class6ListProp
        {
            get { return _class6ListProp; }
            set { _class6ListProp = value; }
        }

Yes:

        public List<Class6> Class6ListProp { get; set; }

Properties that return another class, or collection of another class, need to reverse engineer a association for C#.  Without this reverse engineering, the reverse engineering of properties is not usable with C# without a lot of manual work.


In the mean time - has anyone come up with a workaround or solution that doesn't involve updating all the models manually?

TIA - Jeff Odell

riku100

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering of C# Auto-Properties
« Reply #1 on: August 28, 2012, 07:39:21 pm »
Jeff, Did you get any feedback on this problem?

srobinet

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering of C# Auto-Properties
« Reply #2 on: September 05, 2012, 09:06:58 am »
I was hoping for a solution to this as well.  For now we could manually create the associations but as more of our code is being written with the auto-properties, it's quickly going to become impractical to do so.

MarcioMonego

  • EA Novice
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Re: Reverse Engineering of C# Auto-Properties
« Reply #3 on: March 24, 2016, 06:39:46 am »
I know it's a very old post but since Sparx didn't answer our very valuable question here is a workaround for reverse engineering and see the C# auto-implemented properties showing as class associations.

First of all this method is intend to help on just reverse engineering to facilitate the comprehension of large models AND NOT for bidirectional code engineering.

The key for the problem is the absence of an auto generated backing field for the C# compiler to represent the true UML association that cannot be represented based on methods as already stated by Jeff.

Then isted of making reverse engineering based on source code files (.cs or what ever) make reverse engineering base on .Net binaries with Disassembly method (You be prompted to show the path to Peverify.exe, found on Microsoft SDKs). This way the assembly WILL contain the auto generated backing fields necessary to show the correct UML association.

Disadvantages:
You cannot show source code on any element as all will be fixed to file.dll/exe used on reverse engineer;
You cannot edit this reverse engineered elements to synchronize with original code if you have it;
You will see all anonymous types your code have;

But anyway it is still useful.

Hope it can help some of you!

Márcio Mônego