Esempio n. 1
0
        private object FuncInvoker <Arg1T, ResultT>(Closure closure, ExecutionNode[] argumentFns)
        {
            var arg1 = closure.Unbox <Arg1T>(argumentFns[0].Run(closure));

            return(((Func <Arg1T, ResultT>) this.fn).Invoke(arg1));
        }
Esempio n. 2
0
 private object FuncInvoker <ResultT>(Closure closure, ExecutionNode[] argumentFns)
 {
     return(((Func <ResultT>) this.fn).Invoke());
 }
Esempio n. 3
0
        /// <inheritdoc />
        public override object Run(Closure closure)
        {
            var operand = closure.Unbox <object>(this.operandNode.Run(closure));

            if (operand == null && (this.targetType.CanBeNull || this.isTargetTypeNullable))
            {
                return(null);
            }

            var operandType = closure.GetType(operand);
            var convertType = this.convertExpression.NodeType;

            if (convertType != ExpressionType.Convert)
            {
                convertType = ExpressionType.ConvertChecked;
            }

            // un-box
            if ((this.sourceType == typeof(object) || this.sourceType == typeof(ValueType) || this.sourceType.IsInterface) && this.targetType.IsValueType)
            {
                // null un-box
                if (operand == null)
                {
                    throw new NullReferenceException(string.Format(Properties.Resources.EXCEPTION_EXECUTION_EXPRESSIONGIVESNULLRESULT, this.convertExpression.Operand));
                }
                // type check for un-box
                if (operandType == this.targetType)
                {
                    return(operand);
                }
                throw new InvalidCastException();
            }
            // box
            else if (this.sourceType.IsValueType && (this.targetType == typeof(object) || this.targetType == typeof(ValueType) || this.targetType.IsInterface))
            {
                // type check for box
                return(this.targetType.IsAssignableFrom(operandType) ? operand : null);
            }
            // to enum
            else if (this.targetType.IsEnum && (this.sourceType == typeof(byte) ||
                                                this.sourceType == typeof(sbyte) ||
                                                this.sourceType == typeof(short) ||
                                                this.sourceType == typeof(ushort) ||
                                                this.sourceType == typeof(int) ||
                                                this.sourceType == typeof(uint) ||
                                                this.sourceType == typeof(long) ||
                                                this.sourceType == typeof(ulong)))
            {
                if (operand == null)
                {
                    throw new NullReferenceException(string.Format(Properties.Resources.EXCEPTION_EXECUTION_EXPRESSIONGIVESNULLRESULT, this.convertExpression.Operand));
                }

                operand = Intrinsic.InvokeConversion(closure, operand, Enum.GetUnderlyingType(this.targetType), this.convertExpression.NodeType, null);
                return(Enum.ToObject(this.targetType, closure.Unbox <object>(operand)));
            }
            // from enum
            else if (this.sourceType.IsEnum && (this.targetType == typeof(byte) ||
                                                this.targetType == typeof(sbyte) ||
                                                this.targetType == typeof(short) ||
                                                this.targetType == typeof(ushort) ||
                                                this.targetType == typeof(int) ||
                                                this.targetType == typeof(uint) ||
                                                this.targetType == typeof(long) ||
                                                this.targetType == typeof(ulong)))
            {
                if (operand == null)
                {
                    throw new NullReferenceException(string.Format(Properties.Resources.EXCEPTION_EXECUTION_EXPRESSIONGIVESNULLRESULT, this.convertExpression.Operand));
                }

                operand = Convert.ChangeType(closure.Unbox <object>(operand), Enum.GetUnderlyingType(this.sourceType));
                operand = Intrinsic.InvokeConversion(closure, operand, this.targetType, this.convertExpression.NodeType, null);
                return(operand);
            }
            // from nullable
            if (this.targetType.IsValueType && this.isSourceTypeNullable)
            {
                if (operand == null)
                {
                    throw new NullReferenceException(string.Format(Properties.Resources.EXCEPTION_EXECUTION_EXPRESSIONGIVESNULLRESULT, this.convertExpression.Operand));
                }

                operand = Intrinsic.InvokeConversion(closure, operand, this.targetType, this.convertExpression.NodeType, null);
            }
            else if (this.targetType.IsAssignableFrom(operandType))
            {
                return(operand);
            }

            return(Intrinsic.InvokeConversion(closure, operand, this.targetType, convertType, this.operation));
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override object Run(Closure closure)
        {
            var parameter = closure.Locals[LOCAL_FIRST_PARAMETER + this.parameterIndex];

            return(parameter);
        }
Esempio n. 5
0
 /// <inheritdoc />
 public override object Run(Closure closure)
 {
     return(this.unaryExpression.Operand);
 }
Esempio n. 6
0
        /// <inheritdoc />
        public override object Run(Closure closure)
        {
            var target = closure.Unbox <object>(closure.Locals[LOCAL_OPERAND1]);

            if (this.bindingsByMember.Count == 0)
            {
                return(target);
            }

            foreach (var bindings in this.bindingsByMember)
            {
                var member       = bindings.Key;
                var fieldInfo    = member as FieldInfo;
                var propertyInfo = member as PropertyInfo;
                var bindTarget   = default(object);

                if (fieldInfo != null)
                {
                    if (fieldInfo.IsStatic == false && target == null)
                    {
                        throw new NullReferenceException();
                    }
                    bindTarget = fieldInfo.GetValue(target);
                }
                else if (propertyInfo != null)
                {
                    var getMethod = propertyInfo.GetAnyGetter();
                    if (getMethod.IsStatic == false && target == null)
                    {
                        throw new NullReferenceException();
                    }

                    bindTarget = propertyInfo.GetValue(target, null);
                }
                else
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.EXCEPTION_EXECUTION_INVALIDMEMBERFOREXPRESSION, member));
                }

                foreach (var bind in bindings)
                {
                    if (ReferenceEquals(bind.MemberAssignments, MemberAssignmentsNode.Empty) == false)
                    {
                        closure.Locals[LOCAL_OPERAND1] = bindTarget;
                        bind.MemberAssignments.Run(closure);
                    }

                    if (ReferenceEquals(bind.MemberListBindings, MemberListBindingsNode.Empty) == false)
                    {
                        closure.Locals[LOCAL_OPERAND1] = bindTarget;
                        bind.MemberListBindings.Run(closure);
                    }

                    if (ReferenceEquals(bind.MemberMemberBindings, Empty) == false)
                    {
                        closure.Locals[LOCAL_OPERAND1] = bindTarget;
                        bind.MemberMemberBindings.Run(closure);
                    }
                }
            }
            return(target);
        }