ClrDataDescriptor.cs 913 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Reflection;
  2. using Jint.Native;
  3. namespace Jint.Runtime.Descriptors.Specialized
  4. {
  5. public sealed class ClrDataDescriptor : PropertyDescriptor
  6. {
  7. private readonly PropertyInfo _propertyInfo;
  8. private readonly object _item;
  9. private JsValue? _value;
  10. public ClrDataDescriptor(Engine engine, PropertyInfo propertyInfo, object item)
  11. {
  12. _propertyInfo = propertyInfo;
  13. _item = item;
  14. _value = JsValue.FromObject(engine, _propertyInfo.GetValue(_item, null));
  15. Writable = propertyInfo.CanWrite;
  16. }
  17. public override JsValue? Value
  18. {
  19. get
  20. {
  21. return _value;
  22. }
  23. set
  24. {
  25. _value = value;
  26. _propertyInfo.SetValue(_item, _value.GetValueOrDefault().ToObject(), null);
  27. }
  28. }
  29. }
  30. }