Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: jrEA 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?
-
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
-
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
-
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.
-
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
-
We'll probably have the same problem and I think I'll just solve ti through code generation templates for now...
-
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.
-
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.
-
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.
-
What did your parameterized class generate to? Not a generic interface, right?
-
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