示例#1
0
        public override List <object> Call(Args args)
        {
            object[] target_args = new object[param_arr.Length];
            for (int idx = 0; idx < param_arr.Length; idx++)
            {
                var    param = param_arr[idx];
                object arg;
                if (!args.name_args.TryGetValue(param.Name, out arg))
                {
                    if (idx >= args.args.Count)
                    {
                        if (param.HasDefaultValue)
                        {
                            arg = param.DefaultValue;
                        }
                        else
                        {
                            throw new Exception($"{ctor.DeclaringType}.ctor miss {idx} arg");
                        }
                    }
                    else
                    {
                        arg = args.args[idx];
                    }
                }
                target_args[idx] = ExtWrap.CheckAndConvertFromSSToSS(arg, param.ParameterType);
            }

            var ret = ctor.Invoke(target_args);

            return(new List <object>()
            {
                ret
            });
        }
示例#2
0
        public override List <object> Call(Args args)
        {
            object that = null;

            object[] target_args = new object[param_arr.Length];
            int      target_base = 0;
            int      arg_base    = 0;

            if (that_type != null)
            {
                // ss 对象方法
                that = args[Config.MAGIC_THIS] ?? args.that;
                if (!that_type.IsInstanceOfType(that))
                {
                    throw new Exception($"this does not match, expect {that_type} got {that?.GetType()}. ExtFunc:{method.DeclaringType}.{method.Name} is_static:{method.IsStatic}");
                }
                // 静态方法 to ss对象方法需要特殊处理,将this放到第一个参数的位置
                if (method.IsStatic)
                {
                    target_args[target_base++] = that;
                    that = null;
                }
            }
            else
            {
                // ss 全局方法
                // c#对象方法 to ss全局方法需要特殊处理,从参数列表里提取this
                if (!method.IsStatic)
                {
                    that     = args[Config.MAGIC_THIS] ?? args[0];
                    arg_base = 1;// 不管怎么样,第一个参数都当成this,被吃掉
                    if (!method.DeclaringType.IsInstanceOfType(that))
                    {
                        throw new Exception($"fisrt arg does not match, expect {method.DeclaringType} got {that?.GetType()}. ExtFunc:{method.DeclaringType}.{method.Name} is_static:False");
                    }
                }
            }

            for (int idx = target_base; idx < param_arr.Length; idx++)
            {
                var    param = param_arr[idx];
                object arg;
                if (!args.name_args.TryGetValue(param.Name, out arg))
                {
                    if (idx - target_base + arg_base >= args.args.Count)
                    {
                        if (param.HasDefaultValue)
                        {
                            arg = param.DefaultValue;
                        }
                        else
                        {
                            throw new Exception($"miss {idx - target_base + arg_base} arg. ExtFunc:{method.DeclaringType}.{method.Name} is_static:{method.IsStatic}");
                        }
                    }
                    else
                    {
                        arg = args.args[idx - target_base + arg_base];
                    }
                }
                target_args[idx] = ExtWrap.CheckAndConvertFromSSToSS(arg, param.ParameterType);
            }

            var           ret = method.Invoke(that, target_args);
            List <object> ls  = new List <object>()
            {
                ret
            };

            for (int idx = 0; idx < param_arr.Length; idx++)
            {
                var param = param_arr[idx];
                if (param.IsOut || param.ParameterType.IsByRef)
                {
                    ls.Add(target_args[idx]);
                }
            }

            return(ls);
        }
示例#3
0
 public void Register(string name, ExtWrap wrap)
 {
     // todo check name
     wraps[name] = wrap;
 }