public static IFlowPort GetOrCreatePort(this IFlowPortAttribute self, INode node) { var port = (IFlowPort)((IPortAttribute)self).GetOrCreatePort(node); port.Definition(node, self); return(port); }
public void Definition(INode node, IFlowPortAttribute info) { Id = new PortId(node.NodeId, info.Name); Node = node; Name = info.Name; Direction = info.Direction; Capacity = info.Capacity; GraphPort = info.GraphPort; if (info.CallbackInfo == null) { return; } var parameters = info.CallbackInfo.GetParameters(); if (parameters.Length != 1) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' has {parameters.Length} parameter(s). Can only accept 1 parameter of type 'IFlow'"); return; } var paramType = parameters[0].ParameterType; if (paramType != FlowType) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' has 1 parameter that takes type '{paramType}'. Can only accept 1 parameter of type 'IFlow'"); return; } if (VoidType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _simpleCallback = (Action <IFlow>)info.CallbackInfo.CreateDelegate(SimpleCallbackType, node); _callbackType = CallbackTypes.Simple; } if (FlowPortType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _syncCallback = (Func <IFlow, IFlowPort>)info.CallbackInfo.CreateDelegate(SyncCallbackType, node); _callbackType = CallbackTypes.Sync; } if (EnumerableType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _asyncCallback = (Func <IFlow, IEnumerable>)info.CallbackInfo.CreateDelegate(AsyncCallbackType, node); _callbackType = CallbackTypes.Async; } if (_callbackType == CallbackTypes.None) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' did not have one of the following method signatures [Action<IFlow>, Func<IFlow, IFlowPort>, Func<IFlow, IEnumerable>]"); } }