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 Foo<T>
  12. {
  13. private bool isModified=false;
  14. private T _value;
  15.  
  16. public T Value
  17. {
  18. get
  19. {
  20. return _value;
  21. }
  22. set
  23. {
  24. isModified = true;
  25. _value = value;
  26. }
  27. }
  28. public Foo(T value)
  29. {
  30. _value = value;
  31.  
  32. }
  33.  
  34. public bool IsModified()
  35. {
  36. return isModified;
  37. }
  38. }
  39.  
  40. public class Bar
  41. {
  42. public Foo<int> CustomInt { get; set; } = new Foo<int>(5);
  43. public Foo<bool> CustomBool { get; set; } = new Foo<bool>(false);
  44. }
  45.  
  46.  
  47. class Program
  48. {
  49. static void Main(string[] args)
  50. {
  51. var changed = false;
  52. var bar = new Bar();
  53.  
  54. bar.CustomBool.Value = true;
  55.  
  56. var qqq = bar.GetType().GetProperties();
  57.  
  58. var props = bar.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericTypeDefinition()==typeof(Foo<>) );
  59. foreach (var prop in props)
  60. {
  61. if ((bool)(prop.PropertyType.GetMethod("IsModified").Invoke(prop.GetValue(bar), new object[] { })))
  62. changed = true;
  63. }
  64. Console.WriteLine(changed);
  65. Console.ReadLine();
  66. }
  67. }
  68.  
  69. public class TestController
  70. {
  71. }
  72. }
  73.  
Success #stdin #stdout 0.03s 15688KB
stdin
Standard input is empty
stdout
True