Mustache.Scope.CreateChildScope C# (CSharp) Method

CreateChildScope() public method

Creates a child scope that searches for keys in a default dictionary of key/value pairs.
public CreateChildScope ( ) : Scope
return Scope
        public Scope CreateChildScope()
        {
            return CreateChildScope(new Dictionary<string, object>());
        }

Same methods

Scope::CreateChildScope ( object source ) : Scope

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Gets the context to use when building the inner text of the tag.
        /// </summary>
        /// <param name="writer">The text writer passed</param>
        /// <param name="keyScope">The current scope.</param>
        /// <param name="arguments">The arguments passed to the tag.</param>
        /// <returns>The scope to use when building the inner text of the tag.</returns>
        public override IEnumerable <NestedContext> GetChildContext(
            TextWriter writer,
            Scope keyScope,
            Dictionary <string, object> arguments,
            Scope contextScope)
        {
            object value = arguments[collectionParameter];

            if (!(value is IEnumerable enumerable))
            {
                yield break;
            }
            int index = 0;

            foreach (object item in enumerable)
            {
                NestedContext childContext = new NestedContext()
                {
                    KeyScope     = keyScope.CreateChildScope(item),
                    Writer       = writer,
                    ContextScope = contextScope.CreateChildScope(),
                };
                childContext.ContextScope.Set("index", index);
                yield return(childContext);

                ++index;
            }
        }
All Usage Examples Of Mustache.Scope::CreateChildScope