LazyPropertyDescriptor.cs 675 B

123456789101112131415161718192021222324
  1. using System;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Descriptors.Specialized
  4. {
  5. internal sealed class LazyPropertyDescriptor : PropertyDescriptor
  6. {
  7. private readonly object _state;
  8. private readonly Func<object, JsValue> _resolver;
  9. internal LazyPropertyDescriptor(object state, Func<object, JsValue> resolver, PropertyFlag flags)
  10. : base(null, flags | PropertyFlag.CustomJsValue)
  11. {
  12. _state = state;
  13. _resolver = resolver;
  14. }
  15. protected internal override JsValue CustomValue
  16. {
  17. get => _value ??= _resolver(_state);
  18. set => _value = value;
  19. }
  20. }
  21. }