Newbie GoPort question

What I am trying to do is have my ports store custom data and sometimes access them through GoIconicNode.Ports
Subclassing GoPort and keeping custom data in new data members does not work as I don’t seem to be able to cast GoPorts from GoIconicNode.Ports to the subclass.
and if I try this:

public class PortProperties
{
public String Text;
public PortProperties(String text)
{
this.Text = text;
}
}
public class CustomPort : GoPort
{
public ElectricalPort(String text)
{
this.UserObject = new PortProperties(text);
}
}
the Text property seems to be null whenever ports are accessed through GoIconicNode.Ports and UserObject cast to PortProperties
ports are created and added via GoIconicNode.Add(new CustomPort(“My text”))
Appreciate any comments!

That should work fine. I just used the following:
[Serializable]
public class PortProperties {
public String Text;
public PortProperties(String text) {
this.Text = text;
}
}
[Serializable]
public class CustomPort : GoPort {
public CustomPort(String text) {
this.UserObject = new PortProperties(text);
}
public override string GetToolTip(GoView view) {
PortProperties pp = this.UserObject as PortProperties;
if (pp != null) {
return pp.Text;
}
return null;
}
}
and then tried it with:
GoIconicNode n = new GoIconicNode();
n.Initialize(null, “star.gif”, “extra”);
n.Add(new CustomPort(“My text”));
goView1.Document.Add(n);
And when you hover over the port, it shows “My text” as the tooltip.
Furthermore, by adding the [Serializable] attribute, you’ll be able to copy-and-paste these nodes.

Thanks, walter, the text did show up,
as I tried to access the ports through GoIconicNode.Ports in a loop, I added a check:
foreach (GoPort port in MyNode.Ports)
{
if (port.UserObject is PortProperties)
{
… access ((PortProperties)port.UserObject).Text …
}
}
and it worked. I only add CustomPorts to the node though. Does a node come with port/ports by default?

That depends on the kind of node.
GoNode is just a group that implements IGoNode and some other stuff. Initially it is empty, so you need to add everything yourself.
GoBasicNode, GoIconicNode, GoBoxNode all normally have a single port. But you can add ports or other objects if you choose.
GoSimpleNode normally has two ports, one each on opposite sides.
GoTextNode normally has four ports, one in the middle of each side.
GoGeneralNode and GoMultiTextNode start off with no ports, but as you initialize them they normally get ports. And they make it easy to add more, or remove them.
GoSubGraph normally has no ports of its own. It does implement a Port property, to handle the common case where one thinks of the subgraph as being a node with a single port. And of course you can add ports directly on the subgraph, as well as indirectly from the ports that are on the nodes that you add to the subgraph.

Understood! I will probably end up taking that port out in a GoIconicNode subclass constructor,
this solves it,
Many thanks for quick replies!