/// <summary> /// Gets the last arg allowed to be consumed /// </summary> /// <param name="request">The request.</param> /// <returns>The last arg allowed to be consumed</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static string Last(this ConsumptionRequest request) { var from = request.AllToBeConsumed().ToList(); if (!from.Any()) { throw new ArgumentOutOfRangeException(); } return(from.Last()); }
/// <summary> /// Consumes the specified instance. /// </summary> /// <param name="instance">The instance.</param> /// <param name="request">The request.</param> /// <returns>ConsumptionResult.</returns> /// <exception cref="MissingValueException"></exception> public virtual ConsumptionResult Consume(object instance, ConsumptionRequest request) { try { if (request.Max < MinRequired) { throw new MissingValueException(Parser, $"Switch {this} expected to have at least {MinRequired} values, but was told it can only have {request.Max}. Are you sure you passed enough values to satisfy the switch?"); } HasBeenConsumed = true; var values = request.AllToBeConsumed().Take(MaxAllowed).ToArray(); ConsumeCallback(instance, values); return(new ConsumptionResult(request.Info, values.Length, this)); } catch (ParseException pe) { return(new ConsumptionResult(pe)); } }