Associates parameters to their argument values.
Example #1
0
 private static ArgumentCollection getArguments(TagDefinition definition, Match match)
 {
     ArgumentCollection collection = new ArgumentCollection();
     List<Capture> captures = match.Groups["argument"].Captures.Cast<Capture>().ToList();
     List<TagParameter> parameters = definition.Parameters.ToList();
     if (captures.Count > parameters.Count)
     {
         string message = String.Format(Resources.WrongNumberOfArguments, definition.Name);
         throw new FormatException(message);
     }
     if (captures.Count < parameters.Count)
     {
         captures.AddRange(Enumerable.Repeat((Capture)null, parameters.Count - captures.Count));
     }
     foreach (var pair in parameters.Zip(captures, (p, c) => new { Capture = c, Parameter = p }))
     {
         if (pair.Capture == null)
         {
             if (pair.Parameter.IsRequired)
             {
                 string message = String.Format(Resources.WrongNumberOfArguments, definition.Name);
                 throw new FormatException(message);
             }
             collection.AddArgument(pair.Parameter, null);
         }
         else
         {
             collection.AddArgument(pair.Parameter, pair.Capture.Value);
         }
     }
     return collection;
 }
 /// <summary>
 /// Initializes a new instance of a CompoundGenerator.
 /// </summary>
 /// <param name="definition">The tag that the text is being generated for.</param>
 /// <param name="arguments">The arguments that were passed to the tag.</param>
 public CompoundGenerator(TagDefinition definition, ArgumentCollection arguments)
 {
     _definition = definition;
     _arguments = arguments;
     _primaryGenerators = new LinkedList<IGenerator>();
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of an InlineGenerator.
 /// </summary>
 /// <param name="definition">The tag to render the text for.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 public InlineGenerator(TagDefinition definition, ArgumentCollection arguments)
 {
     _definition = definition;
     _arguments = arguments;
 }