Ejemplo n.º 1
0
        public override string ToString()
        {
            var b = new StringBuilder();

            b.AppendFormat("Calling Method: {0,30:G}\n", GetMethodName(CallingMethod));
            b.AppendFormat("Target Method: {0,30:G}\n", GetMethodName(TargetMethod));
            b.AppendLine("Arguments:");
            foreach (var parameter in TargetMethod.GetParameters())
            {
                object value = (Arguments[parameter.Position] ?? "(null)");
                b.AppendFormat("\t{0,10:G}: {1}\n", parameter.Name, value);
            }
            b.AppendLine();
            return(b.ToString());
        }
        private void OnTargetMethodChanged()
        {
            OutputPins.Clear();
            InputPins.Clear();

            CKlaxScriptRegistry registry = CKlaxScriptRegistry.Instance;

            registry.TryGetFunctionInfo(TargetMethod, out CKlaxScriptFunctionInfo outFunctionInfo);

            Name = outFunctionInfo.displayName;

            if (TargetMethod.ReturnType != typeof(void))
            {
                COutputPin returnOutput = new COutputPin()
                {
                    Name = "Return",
                    Type = TargetMethod.ReturnType,
                };
                OutputPins.Add(returnOutput);
            }

            if (!TargetMethod.IsStatic)
            {
                CInputPin targetObjectInput = new CInputPin()
                {
                    Name                 = "Target",
                    Type                 = TargetMethod.DeclaringType,
                    Literal              = null,
                    SourceNode           = null,
                    SourceParameterIndex = -1,
                    StackIndex           = -1,
                };
                InputPins.Add(targetObjectInput);
            }

            ParameterInfo[] methodParameters = TargetMethod.GetParameters();
            for (var index = 0; index < methodParameters.Length; index++)
            {
                ParameterInfo parameter   = methodParameters[index];
                Type          elementType = parameter.ParameterType;
                if (parameter.ParameterType.IsByRef)
                {
                    elementType = parameter.ParameterType.GetElementType();
                    if (!parameter.IsIn)
                    {
                        m_additionalReturns.Add(index);
                        COutputPin output = new COutputPin()
                        {
                            Name = parameter.Name,
                            Type = elementType,
                        };
                        OutputPins.Add(output);
                    }
                }

                if (parameter.IsOut)
                {
                    continue;
                }

                CInputPin input = new CInputPin()
                {
                    Name                 = outFunctionInfo.inputParameterNames[index],
                    Type                 = elementType,
                    SourceNode           = null,
                    SourceParameterIndex = -1,
                    StackIndex           = -1,
                };

                input.Literal = input.Type.IsValueType ? Activator.CreateInstance(input.Type) : null;
                InputPins.Add(input);

                m_functionProxy = new SKlaxScriptFunctionProxy(outFunctionInfo);
            }
        }