Represents a scope of keys.
 void IGenerator.GetText(KeyScope scope, TextWriter writer)
 {
     Dictionary<string, object> arguments = _arguments.GetArguments(scope);
     IEnumerable<NestedContext> contexts = _definition.GetChildContext(writer, scope, arguments);
     LinkedList<IGenerator> generators;
     if (_definition.ShouldGeneratePrimaryGroup(arguments))
     {
         generators = _primaryGenerators;
     }
     else
     {
         generators = new LinkedList<IGenerator>();
         if (_subGenerator != null)
         {
             generators.AddLast(_subGenerator);
         }
     }
     foreach (NestedContext context in contexts)
     {
         foreach (IGenerator generator in generators)
         {
             generator.GetText(context.KeyScope ?? scope, context.Writer ?? writer);
             if (context.WriterNeedsConsidated)
             {
                 writer.Write(_definition.ConsolidateWriter(context.Writer ?? writer, arguments));
             }
         }
     }
 }
Example #2
0
 private string render(IFormatProvider provider, object source)
 {
     KeyScope scope = new KeyScope(source);
     StringWriter writer = new StringWriter(provider);
     _generator.GetText(scope, writer);
     return writer.ToString();
 }
 /// <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="scope">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, KeyScope scope, Dictionary<string, object> arguments)
 {
     object value = arguments[collectionParameter];
     IEnumerable enumerable = value as IEnumerable;
     if (enumerable == null)
     {
         yield break;
     }
     foreach (object item in enumerable)
     {
         yield return new NestedContext() { KeyScope = scope.CreateChildScope(item), Writer = writer };
     }
 }
 /// <summary>
 /// Substitutes the key placeholders with their respective values.
 /// </summary>
 /// <param name="scope">The current lexical scope.</param>
 /// <returns>A dictionary associating the parameter name to the associated value.</returns>
 public Dictionary<string, object> GetArguments(KeyScope scope)
 {
     Dictionary<string, object> arguments = new Dictionary<string,object>();
     foreach (KeyValuePair<TagParameter, string> pair in _argumentLookup)
     {
         object value;
         if (pair.Value == null)
         {
             value = pair.Key.DefaultValue;
         }
         else
         {
             value = scope.Find(pair.Value);
         }
         arguments.Add(pair.Key.Name, value);
     }
     return arguments;
 }
Example #5
0
 void IGenerator.GetText(KeyScope scope, TextWriter writer)
 {
     writer.Write(Value);
 }
Example #6
0
 /// <summary>
 /// Creates a child scope that searches for keys in the given object.
 /// </summary>
 /// <param name="source">The object to search for keys in.</param>
 /// <returns>The new child scope.</returns>
 public KeyScope CreateChildScope(object source)
 {
     KeyScope scope = new KeyScope(source, this);
     return scope;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of a KeyScope.
 /// </summary>
 /// <param name="source">The object to search for keys in.</param>
 /// <param name="parent">The parent scope to search in if the value is not found.</param>
 internal KeyScope(object source, KeyScope parent)
 {
     _parent = parent;
     _source = source;
 }
Example #8
0
 void IGenerator.GetText(KeyScope scope, TextWriter writer)
 {
     object value = scope.Find(_key);
     writer.Write(_format, value);
 }
Example #9
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="scope">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, KeyScope scope, Dictionary<string, object> arguments)
 {
     object context = arguments[contextParameter];
     yield return new NestedContext() { KeyScope = scope.CreateChildScope(context), Writer = writer };
 }
Example #10
0
 void IGenerator.GetText(KeyScope scope, TextWriter writer)
 {
     Dictionary<string, object> arguments = _arguments.GetArguments(scope);
     _definition.GetText(writer, arguments);
 }
Example #11
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="scope">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 virtual IEnumerable<NestedContext> GetChildContext(TextWriter writer, KeyScope scope, Dictionary<string, object> arguments)
 {
     yield return new NestedContext() { KeyScope = scope, Writer = writer };
 }