Example #1
0
        public void Set(string name, object data, Type type)
        {
            if (_parentContext != null && _parentContext.Exists(name))
            {
                _parentContext.Set(name, data, type);
            }

            SetLocal(name, data, type);
        }
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression valueRight = Right.Evaluate(context);

            if (Left is VariableExpression)
            {
                if ((context.AssignmentPermissions & AssignmentPermissions.Variable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to variable not allowed", this);

                VariableExpression varExpr = (VariableExpression)Left;

                bool exists = context.Exists(varExpr.VarName);

                if (exists && (context.AssignmentPermissions & AssignmentPermissions.ExistingVariable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to existing variable not allowed", this);

                if (!exists && (context.AssignmentPermissions & AssignmentPermissions.NewVariable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to new variable not allowed", this);

                context.Set(varExpr.VarName, valueRight.Value, valueRight.Type);

                return valueRight;
            }

			if (Left is FieldExpression)
			{
				if ((context.AssignmentPermissions & AssignmentPermissions.Property) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to property not allowed", this);

				return ((FieldExpression)Left).Assign(context, valueRight.Value);
			}

            throw new IllegalAssignmentException(this);
        }
Example #3
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression valueRight = Right.Evaluate(context);

            if (Left is VariableExpression)
            {
                if ((context.AssignmentPermissions & AssignmentPermissions.Variable) == AssignmentPermissions.None)
                {
                    throw new IllegalAssignmentException("Assignment to variable not allowed", this);
                }

                VariableExpression varExpr = (VariableExpression)Left;

                bool exists = context.Exists(varExpr.VarName);

                if (exists && (context.AssignmentPermissions & AssignmentPermissions.ExistingVariable) == AssignmentPermissions.None)
                {
                    throw new IllegalAssignmentException("Assignment to existing variable not allowed", this);
                }

                if (!exists && (context.AssignmentPermissions & AssignmentPermissions.NewVariable) == AssignmentPermissions.None)
                {
                    throw new IllegalAssignmentException("Assignment to new variable not allowed", this);
                }

                context.Set(varExpr.VarName, valueRight.Value, valueRight.Type);

                return(valueRight);
            }

            if (Left is FieldExpression)
            {
                if ((context.AssignmentPermissions & AssignmentPermissions.Property) == AssignmentPermissions.None)
                {
                    throw new IllegalAssignmentException("Assignment to property not allowed", this);
                }

                return(((FieldExpression)Left).Assign(context, valueRight.Value));
            }

            if (Left is IndexExpression)
            {
                if ((context.AssignmentPermissions & AssignmentPermissions.Indexer) == AssignmentPermissions.None)
                {
                    throw new IllegalAssignmentException("Assignment to indexer not allowed", this);
                }

                return(((IndexExpression)Left).Assign(context, valueRight.Value));
            }

            throw new IllegalAssignmentException(this);
        }
Example #4
0
        /// <summary>
        /// Checks if a mapping for the supplied parameter exists. Uses a <see cref="LambdaExpression"/> to identify the parameter.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/>.</typeparam>
        /// <typeparam name="TProperty">The <see cref="Type"/> of the property.</typeparam>
        /// <param name="parserContext">The <see cref="IParserContext"/>.</param>
        /// <param name="propertySelector">A <see cref="LambdaExpression"/> which selects the property.</param>
        /// <returns><c>true</c> if the mapping was found; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="parserContext"/>' and '<paramref name="propertySelector"/>' cannot be null. </exception>
        public static Boolean Exists <T, TProperty>([NotNull] this IParserContext parserContext, [NotNull] Expression <Func <T, TProperty> > propertySelector)
        {
            if (parserContext == null)
            {
                throw new ArgumentNullException(nameof(parserContext));
            }

            if (propertySelector == null)
            {
                throw new ArgumentNullException(nameof(propertySelector));
            }

            return(parserContext.Exists(propertySelector));
        }