You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DiagnosticResult.cs 2.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Microsoft.CodeAnalysis;
  2. using System;
  3. namespace TestHelper
  4. {
  5. /// <summary>
  6. /// Location where the diagnostic appears, as determined by path, line number, and column number.
  7. /// </summary>
  8. public struct DiagnosticResultLocation
  9. {
  10. public DiagnosticResultLocation(string path, int line, int column)
  11. {
  12. if (line < -1)
  13. {
  14. throw new ArgumentOutOfRangeException(nameof(line), "line must be >= -1");
  15. }
  16. if (column < -1)
  17. {
  18. throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1");
  19. }
  20. this.Path = path;
  21. this.Line = line;
  22. this.Column = column;
  23. }
  24. public string Path { get; }
  25. public int Line { get; }
  26. public int Column { get; }
  27. }
  28. /// <summary>
  29. /// Struct that stores information about a Diagnostic appearing in a source
  30. /// </summary>
  31. public struct DiagnosticResult
  32. {
  33. private DiagnosticResultLocation[] locations;
  34. public DiagnosticResultLocation[] Locations
  35. {
  36. get
  37. {
  38. if (this.locations == null)
  39. {
  40. this.locations = new DiagnosticResultLocation[] { };
  41. }
  42. return this.locations;
  43. }
  44. set
  45. {
  46. this.locations = value;
  47. }
  48. }
  49. public DiagnosticSeverity Severity { get; set; }
  50. public string Id { get; set; }
  51. public string Message { get; set; }
  52. public string Path
  53. {
  54. get
  55. {
  56. return this.Locations.Length > 0 ? this.Locations[0].Path : "";
  57. }
  58. }
  59. public int Line
  60. {
  61. get
  62. {
  63. return this.Locations.Length > 0 ? this.Locations[0].Line : -1;
  64. }
  65. }
  66. public int Column
  67. {
  68. get
  69. {
  70. return this.Locations.Length > 0 ? this.Locations[0].Column : -1;
  71. }
  72. }
  73. }
  74. }