PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/MSBuild/Microsoft/Build/CommandLine/CommandLineSwitchException.cs

#
C# | 60 lines | 51 code | 9 blank | 0 comment | 4 complexity | c4f02b1d00a68cf253027f140a9453bb 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 CommandLineSwitchException : Exception
  6. {
  7. private string commandLineArg;
  8. private CommandLineSwitchException(string message) : base(message)
  9. {
  10. }
  11. private CommandLineSwitchException(string message, string commandLineArg) : this(message)
  12. {
  13. this.commandLineArg = commandLineArg;
  14. }
  15. internal static void Throw(string messageResourceName, string commandLineArg)
  16. {
  17. Throw(messageResourceName, commandLineArg, new string[] { string.Empty });
  18. }
  19. internal static void Throw(string messageResourceName, string commandLineArg, params string[] messageArgs)
  20. {
  21. string message = Microsoft.Build.Shared.ResourceUtilities.FormatResourceString(messageResourceName, messageArgs);
  22. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(message != null, "The resource string must exist.");
  23. throw new CommandLineSwitchException(message, commandLineArg);
  24. }
  25. internal static void VerifyThrow(bool condition, string messageResourceName, string commandLineArg)
  26. {
  27. if (!condition)
  28. {
  29. Throw(messageResourceName, commandLineArg);
  30. }
  31. }
  32. internal string CommandLineArg
  33. {
  34. get
  35. {
  36. return this.commandLineArg;
  37. }
  38. }
  39. public override string Message
  40. {
  41. get
  42. {
  43. if (this.commandLineArg == null)
  44. {
  45. return base.Message;
  46. }
  47. return (base.Message + Environment.NewLine + Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("InvalidSwitchIndicator", new object[] { this.commandLineArg }));
  48. }
  49. }
  50. }
  51. }