InvalidOptionsException.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Google.ProtocolBuffers.Collections;
  5. namespace Google.ProtocolBuffers.ProtoGen {
  6. /// <summary>
  7. /// Exception thrown to indicate that the options passed were invalid.
  8. /// </summary>
  9. public sealed class InvalidOptionsException : Exception {
  10. private readonly IList<string> reasons;
  11. /// <summary>
  12. /// An immutable list of reasons why the options were invalid.
  13. /// </summary>
  14. public IList<string> Reasons {
  15. get { return reasons; }
  16. }
  17. public InvalidOptionsException(IList<string> reasons)
  18. : base(BuildMessage(reasons)) {
  19. this.reasons = Lists.AsReadOnly(reasons);
  20. }
  21. private static string BuildMessage(IEnumerable<string> reasons) {
  22. StringBuilder builder = new StringBuilder("Invalid options:");
  23. builder.AppendLine();
  24. foreach (string reason in reasons) {
  25. builder.Append(" ");
  26. builder.AppendLine(reason);
  27. }
  28. return builder.ToString();
  29. }
  30. }
  31. }