Function


Node Information
This will get all available functions of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the functions.
General Information
• This node has other options, you can view them by clicking on the info button, this also means according to the node you might be able to add more ports than what is already listed.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Object IN Object ONE FALSE TRUE
Get OUT Object MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Types
{
    [IsNode("Function")]
    public class GetFunction : Node
    {
        Port getfunc = new Port(PortType.OUT, typeof(object), AcceptsLinks.MULTIPLE, "Get");
        Port obj = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "Object");
        public bool Instance
        {
            set { obj.Value = value.ToString(); }
            get
            {
                bool ret = false;
                bool.TryParse(obj.Value, out ret);
                return ret;
            }
        }
        public GetFunction()
        {
            Name = "Function";
            AddPort(obj);
            AddPort(getfunc);
            Instance = true;
            OptionsAvilable = true;
            obj.OnDisconnected = ObjDisconnected;
            obj.CustomAcception = ObjAcception;
            Information = "This will get all available functions of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the functions.";
        }
        bool ObjAcception(Port port)
        {
            if (string.IsNullOrWhiteSpace(ReferenceName))
            {
                if (port != null && port.DataType != null)
                {
                    ReferenceName = port.ParentNode.ReferenceName;
                    ReturnType = port.DataType;
                    CreateMenu(port.DataType);
                }
            }
            else
            {
                ClearMethod();
            }
            return true;
        }
        private void ObjDisconnected(int portCount)
        {
            ClearMethod();
        }
        private void ClearMethod()
        {
            ReferenceName = string.Empty;
            getfunc.Value = string.Empty;
            List<port> prts = new List<port>();
            foreach (var item in Ports)
            {
                if (item.IsExtra)
                {
                    prts.Add(item);
                }
            }
            foreach (var item in prts)
            {
                RemovePort(item, false);
            }
            InfoContextMenu = null;
        }
        private void CreateMenu(Type type)
        {
            InfoContextMenu = GetFunctionsMenu(type, Instance);
        }
        public override void OnFunctionSelected(System.Reflection.MethodInfo methodInfo)
        {
            string nm = ReferenceName;
            ClearMethod();
            ReferenceName = nm;
            getfunc.Value = methodInfo.Name;
            Name = methodInfo.Name;
            getfunc.DataType = methodInfo.ReturnType;
            foreach (var item in methodInfo.GetParameters())
            {
                Port port = new Port(PortType.IN, item.ParameterType, AcceptsLinks.ONE, item.Name, true);
                AddPort(port);
            }
            CreateMenu(ReturnType);
        }
        public override void UpdateResults()
        {
            string par = string.Empty;
            foreach (var port in Ports)
            {
                if (port.IsExtra)
                {
                    par += port.Text + ":" + GetValue(port) + ", ";
                }
            }
            if (par.Length > 2)
            {
                par = par.Remove(par.Length - 2, 2);
            }
            getfunc.Instructions = GetValue(obj) + "." + getfunc.Value + "(" + par + ")";
        }
        public override void OnLoad()
        {
            if (ReturnType != null)
            {
                CreateMenu(ReturnType);
            }
        }
    }
}

</port></port>