/// <summary> /// Parses the given <paramref name="parameters"/> into a <see cref="Query"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="parameters">The parameters which to parse.</param> /// <returns>Returns the <see cref="Query"/>.</returns> /// <exception cref="ArgumentNullException">Throw if <paramref name="context"/> or <paramref name="parameters"/> is null.</exception> /// <exception cref="InvalidOperationException">Thrown if any of the parameters could not be parsed into a query.</exception> public Query Parse(IMansionContext context, IPropertyBag parameters) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (parameters == null) throw new ArgumentNullException("parameters"); // create a copy of the parameters, we do not want to change the parameters here var parametersCopy = parameters.Copy(); // parse the query var query = DoParse(context, parametersCopy); // check to make sure all parameters are eaten if (parametersCopy.Count != 0) throw new InvalidOperationException(string.Format("Could not parse parameters {0} into a query", string.Join(", ", parametersCopy.Names))); // return the created query return query; }