Author Topic: Generics  (Read 6821 times)

jrEA

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Generics
« on: February 16, 2007, 10:08:32 am »
If I have the following code:

public interface IMyInterface<T>
{
 T GetMyObject();
}

public class MyClass : IMyInterface<MyObject>
{
 MyObject GetMyObject();
}

I do not know how to make in EA so that the GetMyObject method in MyClass class changes the return type from T to MyObject automatically when the IMyInterface<MyObject> was specified.

Any ideas?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Generics
« Reply #1 on: February 16, 2007, 10:25:15 am »
Neither do I, but I need to figure this out soon. In the meantime you might want to try the same first steps I will use.
  • Search the forum for information on this subject. Questions about generics have been asked before, and both Sparx and users have posted information.
  • Try some forward and reverse engineering tricks, see what EA does, and what code it generates if you fool around with the settings. Pay attention to the hints you found in the former step so you'll know what to tweak.
HTH, David
No, you can't have it!

JohnWSaundersIII

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: Generics
« Reply #2 on: February 18, 2007, 04:15:38 pm »
I just tried some things, and I can't even find a way to create a generic interface. The interface element doesn't have the detail tab which includes the "Templates" section.

I also tried using a class with a <<interface>> stereotype, but that is generated as a class, not as an interface.

John
John Saunders

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Generics
« Reply #3 on: February 18, 2007, 08:45:30 pm »
Unfortunately, Generic Interfaces cannot currently be modelled in EA, but we are aware of this limitation and hope to address this in a future release.

CleverCoder

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Re: Generics
« Reply #4 on: August 27, 2007, 11:36:00 am »
So... seeing as how C# 3.0 is right around the corner, when do you suppose formal generic support (mainly generic methods) be supported? ;D

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: Generics
« Reply #5 on: August 27, 2007, 12:16:00 pm »
We'll probably have the same problem and I think I'll just solve ti through code generation templates for now...
Recursion definition:
If you don’t understand the definition read "Recursion definition".

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Generics
« Reply #6 on: April 16, 2008, 08:22:25 pm »
Hi Martin -

Did you make any progress in resolving this issue?

I submitted a bug around reverse engineering C# 3.0 constructs.  I received the following:

We do not currently support the C# 3.0 language extensions including partial methods.

 >:(

I have registered this as a feature request on your behalf.


I've replied asking this be prioritized as this makes class modeling and the VS Integration pretty useless on my next two projects.

If you need this feature please put in a prioity request to see if we can get it moving.
« Last Edit: April 16, 2008, 08:22:58 pm by odelljl »

JohnWSaundersIII

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: Generics
« Reply #7 on: April 16, 2008, 11:55:02 pm »
Seeing activity on this thread made me try again. It's still not supported properly.

Depending on how long C# 3.0 support will take, Sparx may wish to consider fixing this problem before finishing C# 3.0 support. As much as generic interfaces are required in order to support LINQ, generic interfaces have existed in C# since Visual Studio 2005. Generic collection interfaces are used fairly heavily. IList<T> would be nice to have.
John Saunders

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Generics
« Reply #8 on: April 17, 2008, 12:45:09 am »
I've had some (very limited) success using parameterized classes for this. I have no idea what would happen if this approach were used in an 'industrial strength' application though.
No, you can't have it!

JohnWSaundersIII

  • EA User
  • **
  • Posts: 50
  • Karma: +0/-0
    • View Profile
Re: Generics
« Reply #9 on: April 17, 2008, 05:38:07 am »
What did your parameterized class generate to? Not a generic interface, right?
John Saunders

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Generics
« Reply #10 on: April 17, 2008, 08:17:40 am »
No, not a generic interface.

But I was able to create classes that had (Of T) -ish syntax, and correctly generate the code. As I said though, I don't know how far this would take me in a complex system model. My application domain was quite subtle, and sensitive to several factors (including generics), but it was also very limited in scope. It is possible that I just found a sweet spot that worked in my specific situation but would break elsewhere.

Sorry I can't offer much help or hope.

The real bottom line is that generics and partials need solid support, keyed to specific languages, and versions as appropriate. At a minimum recent versions of the Java and the .Net world need this, and that covers a pretty large segment of the potential user base.

David
No, you can't have it!