Book a Demo

Author Topic: How to model C# generics?  (Read 2710 times)

togo

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
How to model C# generics?
« on: June 28, 2008, 11:40:38 pm »
I am trying to model a simple class hierarchy using C# generics:

Code: [Select]
public interface Base<T> where T : MyClass2
{
   void something(T param);
}

public class MyClass : Base<MyClass2>
{
  void something(MyClass2 param) { ... }
}

I would like to draw a class diagram for this, but only managed to create the parametrized Base interface.

I can't seem to figure out how to:

    [*] Define the constraint on T so that the EA code generator creates the "where" clause;
    [*] Draw the generalization relationship with the annotation <<bind>> T -> MyClass2 (and make it work with the code generator).
    [/list]

    Am I missing something, or doesn't EA support generics?

    - Togo

    «Midnight»

    • EA Guru
    • *****
    • Posts: 5651
    • Karma: +0/-0
    • That nice Mister Grey
      • View Profile
    Re: How to model C# generics?
    « Reply #1 on: June 30, 2008, 04:23:06 am »
    EA seems to do this by using a parameterized class. Though the meaning is not strictly the same as it would be for C++ EA seems to make sense of it when the language is set to a .Net dialect.

    Try reverse engineering a simple piece of code and you'll see how EA does it. Once you've seen and played with it once you'll get the drift pretty fast.

    David
    No, you can't have it!

    Eve

    • EA Administrator
    • EA Guru
    • *****
    • Posts: 8110
    • Karma: +119/-20
      • View Profile
    Re: How to model C# generics?
    « Reply #2 on: June 30, 2008, 08:43:16 am »
    There are some limitations on the generics support, but as for your questions... The where clause is contained in a tagged value "genericConstraints
    " http://www.sparxsystems.com/EAUserGuide/index.html?csharp_conventions.htm

    Code engineering won't take into account a bind connector.  On the same dialog you made the base class parameterized you can make the child class instantiated and specify the arguments used.
    « Last Edit: June 30, 2008, 08:43:54 am by simonm »