/// <summary> /// Returns true if this port can connect to specified port /// </summary> public bool CanConnectTo(NodePort port) { // Figure out which is input and which is output NodePort input = null, output = null; if (IsInput) { input = this; } else { output = this; } if (port.IsInput) { input = port; } else { output = port; } // If there isn't one of each, they can't connect if (input == null || output == null) { return(false); } // Disable connection if input and output belongs to same node if (input.node == output.node) { return(false); } // Check input type constraints if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited) { if (!AllowedTypes.Any(t => ((Type)t).IsAssignableFrom(output.ValueType))) { return(false); } } if (input.typeConstraint == XNode.Node.TypeConstraint.Strict) { if (AllowedTypes.All(t => ((Type)t) != output.ValueType)) { return(false); } } // Check output type constraints if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited) { if (!AllowedTypes.Any(t => ((Type)t).IsAssignableFrom(input.ValueType))) { return(false); } } if (output.typeConstraint == XNode.Node.TypeConstraint.Strict) { if (AllowedTypes.All(t => ((Type)t) != input.ValueType)) { return(false); } } // Success return(true); }