fork download
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4.  
  5. namespace SO16515341
  6. {
  7. class RestMethods
  8. {
  9. static void Main()
  10. {
  11. Console.WriteLine(A.Test);
  12. A.Clear();
  13. Console.WriteLine(A.Test);
  14. }
  15.  
  16. public static void ClearAllStaticValues(Type t)
  17. {
  18. var varList = t.GetFields(BindingFlags.NonPublic | BindingFlags.Static);
  19. varList.Where(x => x.FieldType == typeof(Int32)).ToList().ForEach(x => x.SetValue(null, 0));
  20. }
  21. }
  22.  
  23. public class A
  24. {
  25. private static int test = 100;
  26.  
  27. public static int Test { get { return test; } }
  28. public static void Clear()
  29. {
  30. //static member
  31. RestMethods.ClearAllStaticValues(typeof(A));
  32. }
  33.  
  34. public void ClearInstance()
  35. {
  36. //instance member
  37. RestMethods.ClearAllStaticValues(GetType());
  38. }
  39. }
  40. }
  41.  
Success #stdin #stdout 0.04s 33968KB
stdin
Standard input is empty
stdout
100
0