1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00

Change the serialised type of dynamic port lists defined as lists/arrays to match the respective element type. (#232)

This is logical, given that xNode already draws such dynamic ports as belonging to the element type.
This commit is contained in:
Lumos 2020-02-13 21:48:59 +00:00 committed by GitHub
parent cf8c70203b
commit f9200ae6a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,13 +76,28 @@ namespace XNode {
NodePort backingPort = staticPorts[backingPortName]; NodePort backingPort = staticPorts[backingPortName];
// Update port constraints. Creating a new port instead will break the editor, mandating the need for setters. // 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.direction = backingPort.direction;
listPort.connectionType = backingPort.connectionType; listPort.connectionType = backingPort.connectionType;
listPort.typeConstraint = backingPort.typeConstraint; listPort.typeConstraint = backingPort.typeConstraint;
} }
} }
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>Returns true if the given port is in a dynamic port list.</summary> /// <summary>Returns true if the given port is in a dynamic port list.</summary>
private static bool IsDynamicListPort(NodePort port) { 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 // Ports flagged as "dynamicPortList = true" end up having a "backing port" and a name with an index, but we have