IntegrityChecking.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace SRDebugger.Editor
  5. {
  6. abstract class IntegrityIssue
  7. {
  8. private readonly string _title;
  9. private readonly string _description;
  10. private List<Fix> _fixes;
  11. public string Title
  12. {
  13. get { return _title; }
  14. }
  15. public string Description
  16. {
  17. get { return _description; }
  18. }
  19. public IList<Fix> GetFixes()
  20. {
  21. if (_fixes == null)
  22. {
  23. _fixes = CreateFixes().ToList();
  24. }
  25. return _fixes;
  26. }
  27. protected IntegrityIssue(string title, string description)
  28. {
  29. _title = title;
  30. _description = description;
  31. }
  32. protected abstract IEnumerable<Fix> CreateFixes();
  33. }
  34. abstract class Fix
  35. {
  36. private readonly string _name;
  37. private readonly string _description;
  38. private readonly bool _isAutoFix;
  39. public string Name
  40. {
  41. get { return _name; }
  42. }
  43. public string Description
  44. {
  45. get { return _description; }
  46. }
  47. public bool IsAutoFix
  48. {
  49. get { return _isAutoFix; }
  50. }
  51. protected Fix(string name, string description, bool isAutoFix)
  52. {
  53. _name = name;
  54. _description = description;
  55. _isAutoFix = isAutoFix;
  56. }
  57. public abstract void Execute();
  58. }
  59. class DelegateFix : Fix
  60. {
  61. private readonly Action _fixMethod;
  62. public DelegateFix(string name, string description, Action fixMethod) : base(name, description, true)
  63. {
  64. _fixMethod = fixMethod;
  65. }
  66. public override void Execute()
  67. {
  68. _fixMethod();
  69. }
  70. }
  71. }