Method


Node Information
This will get all available methods of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the methods.
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
Execute IN RUN MULTIPLE FALSE FALSE
Object IN Object ONE FALSE TRUE

Source
namespace Korduene.KGraph.Nodes.Types
{
    [IsNode("Method")]
    public class GetMethod : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Execute");
        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 GetMethod()
        {
            Name = "Method";
            AddPort(run);
            AddPort(obj);
            Instance = true;
            OptionsAvilable = true;
            obj.OnDisconnected = ObjDisconnected;
            obj.CustomAcception = ObjAcception;
            Information = "This will get all available methods of the connected Type. Connect any object to Object Port, click on the InfoButton to see all the methods.";
        }
        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;
            run.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 = GetMethodsMenu(type, Instance);
        }
        public override void OnMethodSelected(System.Reflection.MethodInfo methodInfo)
        {
            string nm = ReferenceName;
            ClearMethod();
            ReferenceName = nm;
            run.Value = methodInfo.Name;
            Name = methodInfo.Name;
            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);
            }
            run.Instructions = GetValue(obj) + "." + run.Value + "(" + par + ");";
        }
        public override void OnLoad()
        {
            if (ReturnType != null)
            {
                CreateMenu(ReturnType);
            }
        }
    }
}

</port></port>