using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SyncEngine.Configuration { /// Raised when required configuration is missing or invalid. public sealed class ConfigurationException : Exception { public ConfigurationException(IEnumerable errors) : base(BuildMessage(errors)) { Errors = errors == null ? new List() : new List(errors); } public ConfigurationException(string message) : base(message) { Errors = new List { message }; } public IList Errors { get; private set; } private static string BuildMessage(IEnumerable errors) { var list = errors == null ? new string[0] : errors.ToArray(); if (list.Length == 0) { return "Configuration is invalid."; } if (list.Length == 1) { return list[0]; } var sb = new StringBuilder(); sb.AppendLine("Configuration is invalid:"); foreach (var error in list) { sb.AppendLine(" - " + error); } return sb.ToString().TrimEnd(); } } }