2
0

IndexerProperty.cs 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. namespace Jint.Tests.TestClasses;
  2. public class IndexedProperty<TIndex, TValue>
  3. {
  4. Action<TIndex, TValue> Setter { get; }
  5. Func<TIndex, TValue> Getter { get; }
  6. public IndexedProperty(Func<TIndex, TValue> getter, Action<TIndex, TValue> setter)
  7. {
  8. Getter = getter;
  9. Setter = setter;
  10. }
  11. public TValue this[TIndex i]
  12. {
  13. get => Getter(i);
  14. set => Setter(i, value);
  15. }
  16. }
  17. public class IndexedPropertyReadOnly<TIndex, TValue>
  18. {
  19. Func<TIndex, TValue> Getter { get; }
  20. public IndexedPropertyReadOnly(Func<TIndex, TValue> getter)
  21. {
  22. Getter = getter;
  23. }
  24. public TValue this[TIndex i]
  25. {
  26. get => Getter(i);
  27. }
  28. }
  29. public class IndexedPropertyWriteOnly<TIndex, TValue>
  30. {
  31. Action<TIndex, TValue> Setter { get; }
  32. public IndexedPropertyWriteOnly(Action<TIndex, TValue> setter)
  33. {
  34. Setter = setter;
  35. }
  36. public TValue this[TIndex i]
  37. {
  38. set => Setter(i, value);
  39. }
  40. }