InfoEntry.cs 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using SRF;
  3. namespace SRDebugger
  4. {
  5. public sealed class InfoEntry
  6. {
  7. public string Title { get; set; }
  8. public object Value
  9. {
  10. get
  11. {
  12. object result;
  13. try
  14. {
  15. result = this._valueGetter();
  16. }
  17. catch (Exception ex)
  18. {
  19. result = "Error ({0})".Fmt(new object[]
  20. {
  21. ex.GetType().Name
  22. });
  23. }
  24. return result;
  25. }
  26. }
  27. public bool IsPrivate { get; private set; }
  28. public static InfoEntry Create(string name, Func<object> getter, bool isPrivate = false)
  29. {
  30. return new InfoEntry
  31. {
  32. Title = name,
  33. _valueGetter = getter,
  34. IsPrivate = isPrivate
  35. };
  36. }
  37. public static InfoEntry Create(string name, object value, bool isPrivate = false)
  38. {
  39. return new InfoEntry
  40. {
  41. Title = name,
  42. _valueGetter = (() => value),
  43. IsPrivate = isPrivate
  44. };
  45. }
  46. private Func<object> _valueGetter;
  47. }
  48. }