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