コード例 #1
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            if (arguments == null)
            {
                arguments = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var methInfo = target.GetMethodInfo(methodIdx);

            if (methInfo.ArgCount < arguments.Count())
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            if (methInfo.ArgCount > arguments.Count())
            {
                throw RuntimeException.TooLittleArgumentsPassed();
            }

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, arguments.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, arguments.ToArray());
            }

            return(retValue);
        }
コード例 #2
0
        protected override void OnInstanceCreation()
        {
            ActivateAsStringOverride();

            base.OnInstanceCreation();
            var methId = GetScriptMethod("ПриСозданииОбъекта", "OnObjectCreate");
            int constructorParamsCount = ConstructorParams.Count();

            if (methId > -1)
            {
                var procInfo = GetMethodInfo(methId);

                int procParamsCount = procInfo.Params.Count();

                int reqParamsCount = procInfo.Params.Count(x => !x.HasDefaultValue);

                if (constructorParamsCount < reqParamsCount || constructorParamsCount > procParamsCount)
                {
                    throw new RuntimeException("Параметры конструктора: "
                                               + "необходимых параметров: " + Math.Min(procParamsCount, reqParamsCount).ToString()
                                               + ", передано параметров " + constructorParamsCount.ToString()
                                               );
                }
                else if (procInfo.Params.Skip(constructorParamsCount).Any(param => !param.HasDefaultValue))
                {
                    throw RuntimeException.TooLittleArgumentsPassed();
                }

                CallAsProcedure(methId, ConstructorParams);
            }
            else
            {
                if (constructorParamsCount > 0)
                {
                    throw new RuntimeException("Конструктор не определен, но переданы параметры конструктора.");
                }
            }
        }
コード例 #3
0
        private static IValue[] GetArgsToPass(ArrayImpl arguments, MethodInfo methInfo)
        {
            var argsToPass = arguments == null ? new IValue[0] : arguments.ToArray();

            if (methInfo.ArgCount < argsToPass.Length)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            if (methInfo.ArgCount > argsToPass.Length)
            {
                throw RuntimeException.TooLittleArgumentsPassed();
            }

            for (int i = 0; i < argsToPass.Length; i++)
            {
                if (!methInfo.Params[i].IsByValue)
                {
                    argsToPass[i] = Variable.Create(argsToPass[i]);
                }
            }

            return(argsToPass);
        }