示例#1
0
        Result EvalFunc(Evaluator evaluater, Result[] argArray)
        {
            if (argArray.Length < 2)
            {
                throw new ArgumentException();
            }

            if (argArray[0] == null || argArray[1] == null)
            {
                throw new ArgumentNullException("argArray[0]");
            }

            object target = argArray[0].Value;

            if (target == null)
            {
                throw new ArgumentException();
            }

            string functionName = ConvertHelper.ToString(argArray[1].Value);

            Type         type         = null;
            BindingFlags bindingFlags = BindingFlags.Default;

            if (target is Type)
            {
                type         = (Type)target;
                target       = null;
                bindingFlags = BindingFlags.Static;
            }
            else
            {
                type         = target.GetType();
                bindingFlags = BindingFlags.Instance;
            }
            bindingFlags |= BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.OptionalParamBinding;

            int length = argArray.Length - 2;

            object[] argValueAry = new object[length];
            for (int i = 0; i < length; i++)
            {
                argValueAry[i] = argArray[i + 2].Value;
            }
            Binder defaultBinder = Type.DefaultBinder;
            object ret           = type.InvokeMember(functionName,
                                                     bindingFlags, defaultBinder, target, argValueAry);

            if (ret != null)
            {
                return(new Result(ret.GetType(), ret));
            }
            return(new Result(null, null));
        }
示例#2
0
        protected override Result DoEval(Evaluator evaluater, Result[] argArray)
        {
            Type type0 = argArray[0].Type;
            Type type1 = argArray[1].Type;

            if (type0 == null && type1 == null)
            {
                return(new Result(null, null));
            }
            else
            {
                if (type0 == typeof(string))
                {
                    return(new Result(ConvertHelper.ToString(argArray[0].Value) + ConvertHelper.ToString(argArray[1].Value)));
                }
                else
                {
                    double ret = System.Convert.ToDouble(argArray[0].Value) + System.Convert.ToDouble(argArray[1].Value);
                    return(new Result(type0, ConvertHelper.ChangeType(ret, type0)));
                }
            }
        }