fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8.  
  9. namespace ConsoleApp3
  10. {
  11. public class BaseFoo
  12. {
  13. protected bool Changed { get; set; } = false;
  14. public bool IsModified()
  15. {
  16. return Changed;
  17. }
  18. }
  19. public class IntFoo : BaseFoo
  20. {
  21. private int _value;
  22.  
  23. public int Value
  24. {
  25. get
  26. {
  27. return _value;
  28. }
  29. set
  30. {
  31. Changed = true;
  32. _value = value;
  33. }
  34. }
  35. public IntFoo(int value)
  36. {
  37. _value = value;
  38.  
  39. }
  40. }
  41.  
  42. public class BoolFoo : BaseFoo
  43. {
  44. private bool _value;
  45.  
  46. public bool Value
  47. {
  48. get
  49. {
  50. return _value;
  51. }
  52. set
  53. {
  54. Changed = true;
  55. _value = value;
  56. }
  57. }
  58. public BoolFoo(bool value)
  59. {
  60. _value = value;
  61.  
  62. }
  63. }
  64.  
  65. public class Bar
  66. {
  67. public IntFoo CustomInt { get; set; } = new IntFoo(5);
  68. public BoolFoo CustomBool { get; set; } = new BoolFoo(false);
  69. }
  70.  
  71.  
  72. class Program
  73. {
  74. static void Main(string[] args)
  75. {
  76. var changed = false;
  77. var bar = new Bar();
  78.  
  79. bar.CustomBool.Value = true;
  80.  
  81.  
  82. var props = bar.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x=> x.PropertyType.BaseType == typeof(BaseFoo));
  83. foreach (var prop in props)
  84. {
  85. if (((BaseFoo)prop.GetValue(bar)).IsModified())
  86. changed = true;
  87. }
  88. Console.WriteLine(changed);
  89. Console.ReadLine();
  90. }
  91. }
  92.  
  93.  
  94. }
  95.  
Success #stdin #stdout 0.03s 15656KB
stdin
Standard input is empty
stdout
True