Exemplo n.º 1
0
        public NodePort(FieldInfo _fieldInfo, PortAttribute _portAttribute)
        {
            fieldName      = _fieldInfo.Name;
            multiple       = _portAttribute.IsMulti;
            direction      = _portAttribute.Direction;
            typeConstraint = _portAttribute.TypeConstraint;

            if (Utility_Attribute.TryGetFieldAttribute(_fieldInfo.DeclaringType, _fieldInfo.Name, out PortTypeAttribute typeAttribute))
            {
                typeQualifiedName = typeAttribute.portType.AssemblyQualifiedName;
            }
            else
            {
                typeQualifiedName = _fieldInfo.FieldType.AssemblyQualifiedName;
            }
        }
        void InitializePorts()
        {
            foreach (var nodePort in Model.Ports)
            {
                Direction   direction   = nodePort.Value.Direction == PortDirection.Input ? Direction.Input : Direction.Output;
                Orientation orientation =
                    Utility_Attribute.TryGetFieldAttribute(Model.GetType(), nodePort.Value.FieldName, out VerticalAttribute vertical) ?
                    Orientation.Vertical : Orientation.Horizontal;

                NodePortView portView = CustomCreatePortView(orientation, direction, nodePort.Value);
                if (portView == null)
                {
                    portView = NodePortView.CreatePV(orientation, direction, nodePort.Value);
                }
                portView.SetUp(nodePort.Value, CommandDispatcher, Owner);
                PortViews[nodePort.Key] = portView;
            }
        }
        static void CachePorts(Type _nodeType)
        {
            List <FieldInfo> fieldInfos = Utility_Reflection.GetFieldInfos(_nodeType);

            foreach (var fieldInfo in fieldInfos)
            {
                // 获取接口特性
                if (!Utility_Attribute.TryGetFieldAttribute(_nodeType, fieldInfo.Name, out PortAttribute portAttribute))
                {
                    continue;
                }

                if (!portCache.ContainsKey(_nodeType))
                {
                    portCache.Add(_nodeType, new List <NodePort>());
                }

                portCache[_nodeType].Add(new NodePort(fieldInfo, portAttribute));
            }
        }