using System; using System.Collections.Generic; namespace mustache { /// /// Defines a tag that changes the scope to the object passed as an argument. /// internal sealed class WithTagDefinition : TagDefinition { private const string contextParameter = "context"; /// /// Initializes a new instance of a WithTagDefinition. /// public WithTagDefinition() : base("with", true) { } /// /// Gets the parameters that can be passed to the tag. /// /// The parameters. protected override TagParameter[] GetParameters() { return new TagParameter[] { new TagParameter(contextParameter) { IsRequired = true } }; } /// /// Gets whether the tag has content. /// public override bool HasBody { get { return true; } } /// /// Gets the tags that come into scope within the tag. /// /// The child tag. protected override TagDefinition[] GetChildTags() { return new TagDefinition[0]; } /// /// Gets the scopes to use for generating the tag's content. /// /// The current scope. /// The arguments that were passed to the tag. /// The scopes to use for generating the tag's content. public override IEnumerable GetChildScopes(KeyScope scope, Dictionary arguments) { object context = arguments[contextParameter]; yield return scope.CreateChildScope(context); } } }