Main Menu
Login
SSL SecureMode
Username:
Password:  
Lost Password?
Register now!
ChangeVision Members Map
Search
Forum Index   -   Topic Index
   How to use of Astah (Pro/SysML/GSN/Com)
     [Class diagram] Exporting generic type parameter to C#

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Thatar
Posted on: 2015/4/4 19:49
Just popping in
Joined: 2015/4/4
From:
Posts: 4
[Class diagram] Exporting generic type parameter to C#
When using generic classes as return type, argument or member: is it possible to get the generic parameter to export to C#? Right now I entered the type parameter (int) into the type modifier field, but the exported code contains an untyped List instead of a List.
webmaster
Posted on: 2015/4/6 17:03
Webmaster
Joined: 2006/4/27
From:
Posts: 287
Re: [Class diagram] Exporting generic type parameter to C#
Hello Thatar,

Thank you very much for your inquiry and we're very sorry for this late reply.
We're looking into this matter and get back to you tomorrow.

Thank you again for your understanding.
webmaster
Posted on: 2015/4/7 11:52
Webmaster
Joined: 2006/4/27
From:
Posts: 287
Re: [Class diagram] Exporting generic type parameter to C#
Hello Thatar,

I apologize for this late reply.

> is it possible to get the generic parameter to export to C#?

Yes, it's possible to export the Class with the generic parameter by using C# in the Class diagram.
Here is the steps to do so;

(1) Create Class and add the Attribute
(2) Delete the Attribute and fill in the "- list : List<Class>"








(3) Click on "Yes"










If you export this model into C# source code, from [Tool] - [C#] - [Export C#], the result you will get is this:

---------------------------------------------------------------------------------------
public class Class0
{
private List<Class> list;

}
---------------------------------------------------------------------------------------

Please do let me know, if there's anything I can do for you.

Best regards,
Thatar
Posted on: 2015/4/8 17:26
Just popping in
Joined: 2015/4/4
From:
Posts: 4
Re: [Class diagram] Exporting generic type parameter to C#
Hello and thank you for your reply.

That did the trick, though I think in your exported code the "<" and ">" symbols got parsed and should be escaped. ( in the forum post)

It's a bit odd that a new class has to be created for every generic parameter usage. Are there any plans to make generic parameters a property of fields/classes/return values?
Thatar
Posted on: 2015/4/8 18:31
Just popping in
Joined: 2015/4/4
From:
Posts: 4
Re: [Class diagram] Exporting generic type parameter to C#
One issue with this method that it is impossible to have two classes of the same name with differing amounts of generic parameters, like Func.

E.g. Func and Func cannot coŽxist, while this is a valid C# assembly.

Apart from this small hiccup C# export works like a charm. Even makes proper XML comments with which I love!
webmaster
Posted on: 2015/4/9 17:33
Webmaster
Joined: 2006/4/27
From:
Posts: 287
Re: [Class diagram] Exporting generic type parameter to C#
Hello Thatar,

Thank you very much for your response.

> It's a bit odd that a new class has to be created for every generic parameter usage.
> Are there any plans to make generic parameters a property of fields/classes/return values?

> One issue with this method that it is impossible to have two classes of the same name with
> differing amounts of generic parameters, like Func.
> E.g. Func and Func cannot coŽxist, while this is a valid C# assembly.

Could you please give us the source code for both of them so that I can understand your request correctly?

Also if you'd like to use "<" and ">", please fill in "& l t ;" and "& g t ;" on this form.
(Actually, there is no space between these letters. I am very sorry for the inconvenience caused.)
Thatar
Posted on: 2015/4/12 22:56
Just popping in
Joined: 2015/4/4
From:
Posts: 4
Re: [Class diagram] Exporting generic type parameter to C#
Apologies for the late reply.

Do you mean C# source code? An example would be:
----------------------
----------------------
class MyClass {
public Func<int,int> MyFuncA;
public Func<int,int,int> MyFuncB;
}
----------------------
----------------------

If you try to recreate this in Astah by making a C# project, adding a class, and adding these two attributes: it breaks on adding MyFuncB (of type Func<int,int>). It adds a question mark to the type parameters of MyFuncA. Screenshot:



When you export it also adds this question mark to the source code. As you can see Astah does not support generic classes that have the same name but a different amount of generic parameters, even though they exist in C#.
webmaster
Posted on: 2015/4/14 18:08
Webmaster
Joined: 2006/4/27
From:
Posts: 287
Re: [Class diagram] Exporting generic type parameter to C#
Hello Thatar,

Thank you very much for giving the source code and I am very sorry for the delay in getting back to you.

> Are there any plans to make generic parameters a property of fields/classes/return values?

Is it what you meant that you'd like to add the "List" for the attribute in the Class diagram?

If so, there are two ways to do so. I'd like to let you know the steps by email, so could you please send me an email to "support@astah.net". My name is Kaori.

> One issue with this method that it is impossible to have two classes of the same name with differing amounts of generic parameters, like Func.
> E.g. Func and Func cannot coŽxist, while this is a valid C# assembly.

As you mentioned, Astah doesn't have the capability of having two classes of the same name with different amounts of generic parameter.

So I've taken it as a request and added to our user-wish list which Astah development team reviews at the time of planning for the future release and they will consider implementing it.

If you have further questions, please feel free to ask me at anytime.

Kaori
midori
Posted on: 2015/4/27 10:21
Developer
Joined: 2006/7/3
From:
Posts: 324
Re: [Class diagram] Exporting generic type parameter to C#
Hello Thatar,

Thank you for your detailed explanation.

Generics can also be created from the property view.

1) Go to [File] - [New By Template] - [b. C_Sharp.asta] to use a C# template file which includes the System package for C#.

2) Create MyClass and MyList attribute in a class diagram as shown below:








3) Input List<int> in the Type field of the Base tab of MyList attribute property view and press Enter.











4) You will be asked to create a new class List<int> and press Yes.














5) List<int> will be created as an anonymous bound class.








Regarding the anonymous bound class, if you drag & drop List<int> from the structure tree to the class diagram and go to [Show Related Elements] in the class popup menu, you will see the following relationship.


















6) Finally, go to [Tool] - [C#] - [Export C#] and export MyClass. The following code will be generated


using System.Collections.Generic;

public class MyClass
{
	private List<int> MyList;

}


Cheers,
Midori
Threaded | Newest First Previous Topic | Next Topic | Top