PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/MSBuild/Microsoft/Build/CommandLine/InitializationException.cs

#
C# | 70 lines | 60 code | 10 blank | 0 comment | 7 complexity | c67b3d3a79d8a3486343caea169db04b MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.CommandLine
  2. {
  3. using Microsoft.Build.Shared;
  4. using System;
  5. internal sealed class InitializationException : Exception
  6. {
  7. private string invalidSwitch;
  8. private InitializationException()
  9. {
  10. }
  11. private InitializationException(string message) : base(message)
  12. {
  13. }
  14. private InitializationException(string message, string invalidSwitch) : this(message)
  15. {
  16. this.invalidSwitch = invalidSwitch;
  17. }
  18. internal static void Throw(string message, string invalidSwitch)
  19. {
  20. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(message != null, "The string must exist.");
  21. throw new InitializationException(message, invalidSwitch);
  22. }
  23. internal static void Throw(string messageResourceName, string invalidSwitch, Exception e, bool showStackTrace)
  24. {
  25. string unformatted = Microsoft.Build.Shared.AssemblyResources.GetString(messageResourceName);
  26. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(unformatted != null, "The resource string must exist.");
  27. if (showStackTrace)
  28. {
  29. unformatted = unformatted + Environment.NewLine + e.ToString();
  30. }
  31. else
  32. {
  33. unformatted = Microsoft.Build.Shared.ResourceUtilities.FormatString(unformatted, new object[] { (e == null) ? string.Empty : e.Message });
  34. }
  35. Throw(unformatted, invalidSwitch);
  36. }
  37. internal static void VerifyThrow(bool condition, string messageResourceName)
  38. {
  39. VerifyThrow(condition, messageResourceName, null);
  40. }
  41. internal static void VerifyThrow(bool condition, string messageResourceName, string invalidSwitch)
  42. {
  43. if (!condition)
  44. {
  45. Throw(messageResourceName, invalidSwitch, null, false);
  46. }
  47. }
  48. public override string Message
  49. {
  50. get
  51. {
  52. if (this.invalidSwitch == null)
  53. {
  54. return base.Message;
  55. }
  56. return (base.Message + Environment.NewLine + Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("InvalidSwitchIndicator", new object[] { this.invalidSwitch }));
  57. }
  58. }
  59. }
  60. }