aboutsummaryrefslogtreecommitdiff
path: root/csharp/ProtoGen/InvalidOptionsException.cs
blob: aee032284ca114878e09dc5667337e0ff8c8a872 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.Collections;

namespace Google.ProtocolBuffers.ProtoGen {
  /// <summary>
  /// Exception thrown to indicate that the options passed were invalid.
  /// </summary>
  public sealed class InvalidOptionsException : Exception {

    private readonly IList<string> reasons;

    /// <summary>
    /// An immutable list of reasons why the options were invalid.
    /// </summary>
    public IList<string> Reasons {
      get { return reasons; }
    }

    public InvalidOptionsException(IList<string> reasons) 
        : base(BuildMessage(reasons)) {
      this.reasons = Lists.AsReadOnly(reasons);
    }

    private static string BuildMessage(IEnumerable<string> reasons) {
      StringBuilder builder = new StringBuilder("Invalid options:");
      builder.AppendLine();
      foreach (string reason in reasons) {
        builder.Append("  ");
        builder.AppendLine(reason);
      }
      return builder.ToString();
    }
  }
}