AccessHelper.cs 856 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Linq;
  3. using YUR.Fit.Core.Models;
  4. namespace BsYurHttpStatus
  5. {
  6. internal static class AccessHelper
  7. {
  8. public static float SuckFloatProperty(this OverlayStatusUpdate instance, string propertyName)
  9. {
  10. Type t;
  11. try
  12. {
  13. t = instance.CalculationMetrics.GetType();
  14. }
  15. catch
  16. {
  17. return -1;
  18. }
  19. var propertyInfos = t.GetProperties();
  20. var i = propertyInfos.FirstOrDefault(x => x.Name == propertyName && x.PropertyType == typeof(float));
  21. if (i == null) return -2;
  22. try
  23. {
  24. return (float)i.GetValue(instance.CalculationMetrics);
  25. }
  26. catch
  27. {
  28. return -3;
  29. }
  30. }
  31. }
  32. }