Esempio n. 1
0
        private static IValue[] GetArgsToPass(ArrayImpl arguments, MethodInfo methInfo)
        {
            var argsToPass = new List <IValue>();

            if (arguments != null)
            {
                argsToPass.AddRange(arguments);
            }

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

            for (int i = 0; i < argsToPass.Count; i++)
            {
                if (!methInfo.Params[i].IsByValue)
                {
                    argsToPass[i] = Variable.Create(argsToPass[i], $"reflectorArg{i}");
                }
            }
            while (argsToPass.Count < methInfo.ArgCount)
            {
                argsToPass.Add(null);
            }

            return(argsToPass.ToArray());
        }
Esempio n. 2
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);
        }
        private IValue[] MapArguments(int methId, IDictionary <string, object> arguments)
        {
            var parameters = GetMethodInfo(methId + GetOwnMethodCount()).Params;

            IValue[] args = new IValue[parameters.Length];

            if (parameters.Length == 0 && arguments.Count != 0)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                var obj  = arguments[parameters[i].Name];
                var type = obj is IValue ? typeof(IValue) : obj.GetType();

                if (obj is DynamicContextWrapper dyn)
                {
                    obj = dyn.UnderlyingObject;

                    if (type == typeof(DynamicContextWrapper))
                    {
                        type = obj.GetType();
                    }
                }

                args[i] = CustomMarshaller.ConvertToIValueSafe(obj, type);
            }

            return(args);
        }
        protected static object[] MarshalArgumentsStrict(IValue[] arguments, Type[] argumentsTypes)
        {
            if (argumentsTypes.Length < arguments.Length)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            object[] marshalledArgs = new object[arguments.Length];
            for (int i = 0; i < arguments.Length; i++)
            {
                marshalledArgs[i] = ContextValuesMarshaller.ConvertParam(arguments[i], argumentsTypes[i]);
            }

            return(marshalledArgs);
        }
Esempio n. 5
0
        private IValue CallStrTemplate(IValue[] arguments)
        {
            var srcFormat = arguments[0].AsString();

            if (srcFormat == String.Empty)
            {
                return(ValueFactory.Create(""));
            }

            var re              = new System.Text.RegularExpressions.Regex(@"(%%)|(%\d+)|(%\D)");
            int matchCount      = 0;
            int passedArgsCount = arguments.Skip(1).Where(x => x != null).Count();
            var result          = re.Replace(srcFormat, (m) =>
            {
                if (m.Groups[1].Success)
                {
                    return("%");
                }

                if (m.Groups[2].Success)
                {
                    matchCount++;
                    var number = int.Parse(m.Groups[2].Value.Substring(1));
                    if (number < 1 || number > 11)
                    {
                        throw new RuntimeException("Ошибка при вызове метода контекста (СтрШаблон): Ошибка синтаксиса шаблона в позиции " + (m.Index + 1));
                    }

                    if (arguments[number] != null)
                    {
                        return(arguments[number].AsString());
                    }
                    else
                    {
                        return("");
                    }
                }

                throw new RuntimeException("Ошибка при вызове метода контекста (СтрШаблон): Ошибка синтаксиса шаблона в позиции " + (m.Index + 1));
            });

            if (passedArgsCount > matchCount)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            return(ValueFactory.Create(result));
        }
Esempio n. 6
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);
        }