Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: defi on July 24, 2012, 02:26:27 am

Title: cast an EA.Element to an Object
Post by: defi on July 24, 2012, 02:26:27 am
Hi!
I created an object Client with all the properties I want this Object to have. Now i want and object of type EA.Element of a Diagram to cast in an object Client. How can i do that?

I tried with
Code: [Select]
EA.Element node;
Client thisNode = (Client)node;

but it doesn't work, it gives me an exception.

Can please someone help me.
Thank you a lot. And please don't tell me that I'm a noob and that I have to start over to study programming. I want some help to solve this easy (for an expert) problem. Thank you  :)
Title: Re: cast an EA.Element to an Object
Post by: Paulus on July 24, 2012, 03:29:44 am
You can't cast an EA.Element to a Client or any other type since you have no control over the creation of instances of EA.Element. You can only obtain references to EA.Element's already created for you by EA.

So, what exactly are you trying to achieve?
Title: Re: cast an EA.Element to an Object
Post by: defi on July 24, 2012, 03:31:55 am
i resolved the thing, with the following code:

Code: [Select]
EA.Element node;
Client thisNode = new Client(node.ElementID);


Thank you for your help.
Title: Re: cast an EA.Element to an Object
Post by: stao on July 24, 2012, 07:40:19 am
Quote
And please don't tell me that I'm a noob and that I have to start over to study programming. I want some help to solve this easy (for an expert) problem

This quote + this solution?

Code: [Select]
EA.Element node;
Client thisNode = new Client(node.ElementID);

i lol'd...
Title: Re: cast an EA.Element to an Object
Post by: Geert Bellekens on July 24, 2012, 03:17:18 pm
I think he should have use something like
Code: [Select]
Client thisNode = ***(Client)node***; The *** indicate the fairy dust, which activates the code magic ;D

Geert