PopGlobal() public method

Pops the previous model context.
Unexpected PopGlobal() not matching a PushGlobal
public PopGlobal ( ) : IScriptObject
return IScriptObject
Esempio n. 1
0
        /// <summary>
        /// Renders this template using the specified object model.
        /// </summary>
        /// <param name="model">The object model.</param>
        /// <returns>A rendering result as a string </returns>
        public string Render(object model = null)
        {
            var scriptObject = new ScriptObject();

            if (model != null)
            {
                scriptObject.Import(model);
            }

            var context = new TemplateContext();

            context.PushGlobal(scriptObject);
            Render(context);
            context.PopGlobal();

            return(context.Output.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Evaluates the template using the specified context
        /// </summary>
        /// <param name="model">An object model to use with the evaluation.</param>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        /// <returns>Returns the result of the last statement</returns>
        public object Evaluate(object model = null)
        {
            var scriptObject = new ScriptObject();

            if (model != null)
            {
                scriptObject.Import(model);
            }

            var context = new TemplateContext {
                EnableOutput = false
            };

            context.PushGlobal(scriptObject);
            var result = Evaluate(context);

            context.PopGlobal();
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Evaluates the template using the specified context
        /// </summary>
        /// <param name="model">An object model to use with the evaluation.</param>
        /// <param name="memberRenamer">The member renamer used to import this .NET object and transitive objects. See member renamer documentation for more details.</param>
        /// <param name="memberFilter">The member filter used to filter members for .NET objects being accessed through the template, including the model being passed to this method.</param>
        /// <exception cref="System.InvalidOperationException">If the template <see cref="HasErrors"/>. Check the <see cref="Messages"/> property for more details</exception>
        /// <returns>Returns the result of the last statement</returns>
        public object Evaluate(object model = null, MemberRenamerDelegate memberRenamer = null, MemberFilterDelegate memberFilter = null)
        {
            var scriptObject = new ScriptObject();

            if (model != null)
            {
                scriptObject.Import(model, renamer: memberRenamer, filter: memberFilter);
            }

            var context = new TemplateContext
            {
                EnableOutput  = false,
                MemberRenamer = memberRenamer,
                MemberFilter  = memberFilter
            };

            context.PushGlobal(scriptObject);
            var result = Evaluate(context);

            context.PopGlobal();
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Renders this template using the specified object model.
        /// </summary>
        /// <param name="model">The object model.</param>
        /// <returns>A rendering result as a string </returns>
        public string Render(object model = null)
        {
            var scriptObject = new ScriptObject();
            if (model != null)
            {
                scriptObject.Import(model);
            }

            var context = new TemplateContext();
            context.PushGlobal(scriptObject);
            Render(context);
            context.PopGlobal();

            return context.Output.ToString();
        }