Beispiel #1
0
        public Method(string name, MethodBase info)
        {
            Name = name;
            Info = info;

            var parameters = info.GetParameters();

            Parameters = parameters
                         .Select(p => new Parameter(p))
                         .ToList();

            ValueParameters = Parameters
                              .Where(p => p.Type == ParameterType.Value)
                              .ToList();

            MondParameterCount         = ValueParameters.Count;
            RequiredMondParameterCount = ValueParameters.Count(p => !p.IsOptional);

            HasParams = Parameters.Any(p => p.Type == ParameterType.Params);

            if (info is MethodInfo methodInfo)
            {
                ReturnConversion = MondFunctionBinder.MakeReturnConversion(methodInfo.ReturnType);
            }
        }
Beispiel #2
0
        private static object[] BuildParameterArray(
            string errorPrefix,
            MethodTable methodTable,
            MondState state,
            MondValue instance,
            MondValue[] args,
            out MethodBase methodBase,
            out ReturnConverter returnConversion)
        {
            Method method = null;

            if (args.Length < methodTable.Methods.Count)
            {
                method = FindMatch(methodTable.Methods[args.Length], args);
            }

            if (method == null)
            {
                method = FindMatch(methodTable.ParamsMethods, args);
            }

            if (method != null)
            {
                methodBase       = method.Info;
                returnConversion = method.ReturnConversion;

                var parameters = method.Parameters;
                var result     = new object[parameters.Count];

                var j = 0;
                for (var i = 0; i < result.Length; i++)
                {
                    var param = parameters[i];

                    switch (param.Type)
                    {
                    case ParameterType.Value:
                        if (j < args.Length)
                        {
                            result[i] = param.Conversion(args[j++]);
                        }
                        else
                        {
                            result[i] = param.Info.DefaultValue;
                        }
                        break;

                    case ParameterType.Params:
                        result[i] = Slice(args, method.MondParameterCount);
                        break;

                    case ParameterType.Instance:
                        result[i] = instance;
                        break;

                    case ParameterType.State:
                        result[i] = state;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                return(result);
            }

            throw new MondBindingException(BindingError.ParameterTypeError(errorPrefix, methodTable));
        }