How to find the associate nodes by node ports and connector's target?

Hi,

For example,

I have two Node(NodeViewModel).

A Node and B Node, connected each by a Connector

A Node have a out port(NodePortViewModel) and the Connector started there and ended in B Node input port.

Today, I want to start from A Node and follow the Connector to find B Node.

I tried the following method but no luck :(


step 1:
(A_node.Ports as ObservableCollection)[0].Info 

The "Info" Object's object type is NodePortWrapper, and this class is internal that means I can't casting "Info" as NodePortWrapper and access it.

step 2:
But in the runtime, I using Visual Studio's tracking feature find in the "Info", it has "OutConnectors" property.

step 3:

This OutConnectors property seen like some collection, and the ConnectorViewModel able to see this connector will targeting what node it point to(TargetNode property)

step 4:
So I try reflection it by using GetType().GetProperty().GetValue(). 

But here is question, the "OutConnectors" property's type is System.Linq.Enumerable.WhereSelectListIterator

It can't casting in the code, for example:

var foo = (A_node.Ports as ObservableCollection)[0].Info.GetType().GetProperty("OutConnectors").GetValue((A_node.Ports as ObservableCollection)[0].Info, null);

object foo can't convert to List or other things.
(foo's type is System.Linq.Enumerable.WhereSelectListIterator

And this code only able run at runtime:
((Enumerable.WhereSelectListIterator)(A_node.Ports as ObservableCollection)[0].Info.GetType().GetProperty("OutConnectors").GetValue((A_node.Ports as ObservableCollection)[0].Info, null)).ToList()[0];

The result will seen the connector between A and B Node.


-----------------------------------------------------------------------

I started doubt is I'm in the right way to get my information?

Or there is better way to get I want?

Thanks!


3 Replies

KR Karkuvel Rajan Shanmugavel Syncfusion Team April 20, 2018 07:34 AM UTC

Hi Nathaniel, 
 
 
To get associated nodes and connector of a Node, please cast Info as INodeInfo and use following properties. 
 
Property 
Explanation 
InConnectors 
To get the incoming connections. 
OutConnectors 
To get the outgoing connection. 
InOutConnectors 
To get all the connectors connected. 
InNeighbors 
To get the parent Nodes connected with a Connector. 
OutNeighbors 
To get the child Nodes connected with a Connector. 
Neighbors 
To get all the Nodes connected with a Connector. 
 
For more details we have provided the CodeExample below. 
 
Code Example: 
 
// Get the first selected Node 
 
SelectorViewModel select = diag.SelectedItems as SelectorViewModel; 
INode node = (select.Nodes as IEnumerable<object>).FirstOrDefault() as INode; 
 
//Iterate through each Children of Selected Node 
 
foreach(var nodes in (node.Info as INodeInfo).OutNeighbors) 
{ 
     //Do something 
}     
  
Regards, 
Karkuvel Rajan.S 



NC Nathaniel Chen April 21, 2018 06:21 AM UTC

Thanks for your replied!

I know how to access those properties now :)


KR Karkuvel Rajan Shanmugavel Syncfusion Team April 23, 2018 08:40 AM UTC

Hi Nathaniel, 
 
Thanks, please let us know whether you need any other assistance. 
 
Regards, 
Karkuvel Rajan.S 


Loader.
Up arrow icon