Exemplo n.º 1
0
            public override object AssignValue(CodeContext context, object value)
            {
                EvaluationAddress addr = _addrs[Index];

                if (addr != null)
                {
                    return(addr.AssignValue(context, value));
                }
                return(null);
            }
Exemplo n.º 2
0
            public override object GetValue(CodeContext context, bool outParam)
            {
                object result = null;

                for (int i = 0; i < _addrs.Count; i++)
                {
                    EvaluationAddress current = _addrs[i];

                    if (current != null)
                    {
                        object val = current.GetValue(context, outParam);
                        if (i == Index)
                        {
                            result = val;
                        }
                    }
                }
                return(result);
            }
        protected override object DoEvaluate(CodeContext context) {
            object instance = null;
            // Evaluate the instance first (if the method is non-static)
            if (!Method.IsStatic) {
                instance = EvaluateInstance(context);
            }

            object[] parameters = new object[_parameterInfos.Length];
            EvaluationAddress[] paramAddrs = new EvaluationAddress[_parameterInfos.Length];
            if (_parameterInfos.Length > 0) {
                int last = parameters.Length;
                for (int i = 0; i < last; i++) {
                    ParameterInfo pi = _parameterInfos[i];

                    if (pi.ParameterType.IsByRef) {
                        paramAddrs[i] = _arguments[i].EvaluateAddress(context);

                        object value = paramAddrs[i].GetValue(context, !IsInputParameter(i));
                        if (IsInputParameter(i)) {
                            parameters[i] = context.LanguageContext.Binder.Convert(
                                value,
                                _parameterInfos[i].ParameterType.GetElementType()
                            );
                        }
                    } else if (IsInputParameter(i)) {
                        Expression arg = _arguments[i];
                        parameters[i] = arg != null ? arg.Evaluate(context) : null;
                    }
                }
            }

            try {
                object res;
                try {
                    // Call the method
                    res = InvokeMethod(instance, parameters);

                    // Return the singleton True or False object
                    if (Type == typeof(Boolean)) {
                        res = RuntimeHelpers.BooleanToObject((bool)res);
                    }
                } finally {
                    // expose by-ref args
                    for (int i = 0; i < _parameterInfos.Length; i++) {
                        if (_parameterInfos[i].ParameterType.IsByRef) {
                            paramAddrs[i].AssignValue(context, parameters[i]);
                        }
                    }
                }

                // back propagate instance on value types if the instance supports it.
                if (_method.DeclaringType != null && _method.DeclaringType.IsValueType && !_method.IsStatic) {
                    _instance.EvaluateAssign(context, instance);
                }

                return res;
            } catch (TargetInvocationException e) {                
                // Unwrap the real (inner) exception and raise it
                throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
            }
        } 
Exemplo n.º 4
0
        protected override object DoEvaluate(CodeContext context)
        {
            object instance = null;

            // Evaluate the instance first (if the method is non-static)
            if (!Method.IsStatic)
            {
                instance = EvaluateInstance(context);
            }

            object[]            parameters = new object[_parameterInfos.Length];
            EvaluationAddress[] paramAddrs = new EvaluationAddress[_parameterInfos.Length];
            if (_parameterInfos.Length > 0)
            {
                int last = parameters.Length;
                for (int i = 0; i < last; i++)
                {
                    ParameterInfo pi = _parameterInfos[i];

                    if (pi.ParameterType.IsByRef)
                    {
                        paramAddrs[i] = _arguments[i].EvaluateAddress(context);

                        object value = paramAddrs[i].GetValue(context, !IsInputParameter(i));
                        if (IsInputParameter(i))
                        {
                            parameters[i] = context.LanguageContext.Binder.Convert(
                                value,
                                _parameterInfos[i].ParameterType.GetElementType()
                                );
                        }
                    }
                    else if (IsInputParameter(i))
                    {
                        Expression arg = _arguments[i];
                        parameters[i] = arg != null?arg.Evaluate(context) : null;
                    }
                }
            }

            try {
                object res;
                try {
                    // Call the method
                    res = InvokeMethod(instance, parameters);

                    // Return the singleton True or False object
                    if (Type == typeof(Boolean))
                    {
                        res = RuntimeHelpers.BooleanToObject((bool)res);
                    }
                } finally {
                    // expose by-ref args
                    for (int i = 0; i < _parameterInfos.Length; i++)
                    {
                        if (_parameterInfos[i].ParameterType.IsByRef)
                        {
                            paramAddrs[i].AssignValue(context, parameters[i]);
                        }
                    }
                }

                // back propagate instance on value types if the instance supports it.
                if (_method.DeclaringType != null && _method.DeclaringType.IsValueType && !_method.IsStatic)
                {
                    _instance.EvaluateAssign(context, instance);
                }

                return(res);
            } catch (TargetInvocationException e) {
                // Unwrap the real (inner) exception and raise it
                throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
            }
        }