mustache.ArgumentCollection.AddArgument C# (CSharp) Method

AddArgument() public method

Associates the given parameter to the key placeholder.
If the key is null, the default value of the parameter will be used.
public AddArgument ( TagParameter parameter, string key ) : void
parameter TagParameter The parameter to associate the key with.
key string The key placeholder used as the argument.
return void
        public void AddArgument(TagParameter parameter, string key)
        {
            _argumentLookup.Add(parameter, key);
        }

Usage Example

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;
 }