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 1.6 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using Microsoft.CodeAnalysis;
  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) throw new ArgumentOutOfRangeException(nameof(line), "line must be >= -1");
  13. if (column < -1) throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1");
  14. Path = path;
  15. Line = line;
  16. Column = column;
  17. }
  18. public string Path { get; }
  19. public int Line { get; }
  20. public int Column { get; }
  21. }
  22. /// <summary>
  23. /// Struct that stores information about a Diagnostic appearing in a source
  24. /// </summary>
  25. public struct DiagnosticResult
  26. {
  27. private DiagnosticResultLocation[] locations;
  28. public DiagnosticResultLocation[] Locations
  29. {
  30. get
  31. {
  32. if (locations == null) locations = new DiagnosticResultLocation[] { };
  33. return locations;
  34. }
  35. set => locations = value;
  36. }
  37. public DiagnosticSeverity Severity { get; set; }
  38. public string Id { get; set; }
  39. public string Message { get; set; }
  40. public string Path => Locations.Length > 0 ? Locations[0].Path : "";
  41. public int Line => Locations.Length > 0 ? Locations[0].Line : -1;
  42. public int Column => Locations.Length > 0 ? Locations[0].Column : -1;
  43. }
  44. }