SetValue() публичный Метод

Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()
public SetValue ( IInternalContextAdapter context, Object value ) : bool
context IInternalContextAdapter context object containing this reference
value Object Object to set as value
Результат bool
Пример #1
0
        /// <summary>   puts the value of the RHS into the context under the key of the LHS
        /// </summary>
        public override bool Render(IInternalContextAdapter context, TextWriter writer)
        {
            /*
             *  get the RHS node, and it's value
             */

            Object value = right.Value(context);

            /*
             * it's an error if we don't have a value of some sort
             */

            if (value == null)
            {
                /*
                 *  first, are we supposed to say anything anyway?
                 */
                if (blather)
                {
                    EventCartridge eventCartridge = context.EventCartridge;

                    bool doIt = true;

                    /*
                     *  if we have an EventCartridge...
                     */
                    if (eventCartridge != null)
                    {
                        doIt = eventCartridge.ShouldLogOnNullSet(left.Literal, right.Literal);
                    }

                    if (doIt)
                    {
                        runtimeServices.Error(
                            string.Format("RHS of #set statement is null. Context will not be modified. {0} [line {1}, column {2}]",
                                          context.CurrentTemplateName, Line, Column));
                    }
                }

                return(false);
            }

            /*
             *  if the LHS is simple, just punch the value into the context
             *  otherwise, use the setValue() method do to it.
             *  Maybe we should always use setValue()
             */

            if (left.ChildrenCount == 0)
            {
                context.Put(leftReference, value);
            }
            else
            {
                left.SetValue(context, value);
            }

            return(true);
        }
Пример #2
0
        /// <summary>   puts the value of the RHS into the context under the key of the LHS</summary>
        /// <param name="context">
        /// </param>
        /// <param name="writer">
        /// </param>
        /// <returns> True if rendering was sucessful.
        /// </returns>
        /// <throws>  IOException </throws>
        /// <throws>  MethodInvocationException </throws>
        public override bool Render(IInternalContextAdapter context, System.IO.TextWriter writer)
        {
            /*
             *  Get the RHS node, and its value
             */

            object value = right.Value(context);

            /*
             * it's an Error if we don't have a value of some sort AND
             * it is not allowed by configuration
             */

            if (!allowNull)
            {
                if (value == null)
                {
                    /*
                     *  first, are we supposed to say anything anyway?
                     */
                    if (logOnNull)
                    {
                        bool doit = EventHandlerUtil.ShouldLogOnNullSet(rsvc, context, left.Literal, right.Literal);

                        if (doit && rsvc.Log.DebugEnabled)
                        {
                            rsvc.Log.Debug("RHS of #set statement is null. Context will not be modified. " + Log.FormatFileString(this));
                        }
                    }

                    string rightReference = null;
                    if (right is ASTExpression)
                    {
                        rightReference = ((ASTExpression)right).LastToken.Image;
                    }
                    EventHandlerUtil.InvalidSetMethod(rsvc, context, leftReference, rightReference, uberInfo);

                    return(false);
                }
            }

            if (value == null && !strictRef)
            {
                string rightReference = null;
                if (right is ASTExpression)
                {
                    rightReference = ((ASTExpression)right).LastToken.Image;
                }
                EventHandlerUtil.InvalidSetMethod(rsvc, context, leftReference, rightReference, uberInfo);

                /*
                 * if RHS is null, remove simple LHS from context
                 * or call setValue() with a null value for complex LHS
                 */
                if (left.GetNumChildren() == 0)
                {
                    context.Remove(leftReference);
                }
                else
                {
                    left.SetValue(context, (object)null);
                }

                return(false);
            }
            else
            {
                /*
                 *  if the LHS is simple, just punch the value into the context
                 *  otherwise, use the setValue() method do to it.
                 *  Maybe we should always use setValue()
                 */

                if (left.GetNumChildren() == 0)
                {
                    context.Put(leftReference, value);
                }
                else
                {
                    left.SetValue(context, value);
                }
            }

            return(true);
        }