Exemple #1
0
        private static NodeReflectionData LoadMethodReflection(MethodInfo method, FuncNodeModuleAttribute moduleAttr)
        {
            var    attr           = method.GetCustomAttribute <FuncNodeAttribute>();
            string name           = attr?.name ?? ObjectNames.NicifyVariableName(method.Name);
            string returnPortName = attr?.returnName ?? "Result";

            // FuncNode.module can override FuncNodeModule.path.
            string path = attr?.module ?? moduleAttr.path;

            // FuncNode.classType can override default class type
            Type classType = attr?.classType ?? typeof(FuncNode);

            var node = new NodeReflectionData()
            {
                type    = classType,
                path    = path?.Split('/'),
                name    = name,
                tooltip = "TODO!",
                method  = method
            };

            ParameterInfo[] parameters = method.GetParameters();

            foreach (var parameter in parameters)
            {
                node.ports.Add(new PortReflectionData()
                {
                    type = parameter.IsOut ?
                           parameter.ParameterType.GetElementType() :
                           parameter.ParameterType,
                    portName  = ObjectNames.NicifyVariableName(parameter.Name),
                    fieldName = parameter.Name,
                    isMulti   = parameter.IsOut,
                    isInput   = !parameter.IsOut
                });
            }

            // Add an output port for the return value if non-void
            if (method.ReturnType != typeof(void))
            {
                node.ports.Add(new PortReflectionData()
                {
                    type      = method.ReturnType,
                    portName  = returnPortName,
                    fieldName = null,
                    isMulti   = true,
                    isInput   = false
                });
            }

            // Merge in any reflection data from the wrapper class itself
            // Specifically if it contains additional ports to include
            node.AddPortsFromClass(classType);

            return(node);
        }
Exemple #2
0
        private static NodeReflectionData LoadMethodReflection(MethodInfo method, FuncNodeModuleAttribute moduleAttr)
        {
            var    attr           = method.GetCustomAttribute <FuncNodeAttribute>();
            string name           = attr?.name ?? ObjectNames.NicifyVariableName(method.Name);
            string returnPortName = attr?.returnName ?? "Result";

            // FuncNode.module can override FuncNodeModule.path.
            string path = attr?.module ?? moduleAttr.path;

            var node = new NodeReflectionData()
            {
                type    = typeof(FuncNode),
                path    = path?.Split('/'),
                name    = name,
                tooltip = "TODO!",
                method  = method
            };

            ParameterInfo[] parameters = method.GetParameters();

            foreach (var parameter in parameters)
            {
                node.ports.Add(new PortReflectionData()
                {
                    type = parameter.IsOut ?
                           parameter.ParameterType.GetElementType() :
                           parameter.ParameterType,
                    portName  = ObjectNames.NicifyVariableName(parameter.Name),
                    fieldName = parameter.Name,
                    isMulti   = parameter.IsOut,
                    isInput   = !parameter.IsOut
                });
            }

            // Add an output port for the return value if non-void
            if (method.ReturnType != typeof(void))
            {
                node.ports.Add(new PortReflectionData()
                {
                    type      = method.ReturnType,
                    portName  = returnPortName,
                    fieldName = null,
                    isMulti   = true,
                    isInput   = false
                });
            }

            return(node);
        }