diff --git a/Scripts/NodeDataCache.cs b/Scripts/NodeDataCache.cs index 24458ec..71931b1 100644 --- a/Scripts/NodeDataCache.cs +++ b/Scripts/NodeDataCache.cs @@ -76,13 +76,28 @@ namespace XNode { NodePort backingPort = staticPorts[backingPortName]; // Update port constraints. Creating a new port instead will break the editor, mandating the need for setters. - listPort.ValueType = backingPort.ValueType; + listPort.ValueType = GetBackingValueType(backingPort.ValueType); listPort.direction = backingPort.direction; listPort.connectionType = backingPort.connectionType; listPort.typeConstraint = backingPort.typeConstraint; } } + /// + /// Extracts the underlying types from arrays and lists, the only collections for dynamic port lists + /// currently supported. If the given type is not applicable (i.e. if the dynamic list port was not + /// defined as an array or a list), returns the given type itself. + /// + private static System.Type GetBackingValueType(System.Type portValType) { + if (portValType.HasElementType) { + return portValType.GetElementType(); + } + if (portValType.IsGenericType && portValType.GetGenericTypeDefinition() == typeof(List<>)) { + return portValType.GetGenericArguments()[0]; + } + return portValType; + } + /// Returns true if the given port is in a dynamic port list. private static bool IsDynamicListPort(NodePort port) { // Ports flagged as "dynamicPortList = true" end up having a "backing port" and a name with an index, but we have