PropertyAccessor.cs 830 B

123456789101112131415161718192021222324252627282930
  1. using System.Reflection;
  2. namespace Jint.Runtime.Interop.Reflection;
  3. internal sealed class PropertyAccessor : ReflectionAccessor
  4. {
  5. private readonly PropertyInfo _propertyInfo;
  6. public PropertyAccessor(
  7. PropertyInfo propertyInfo,
  8. PropertyInfo? indexerToTry = null)
  9. : base(propertyInfo.PropertyType, indexerToTry)
  10. {
  11. _propertyInfo = propertyInfo;
  12. }
  13. public override bool Readable => _propertyInfo.CanRead;
  14. public override bool Writable => _propertyInfo.CanWrite;
  15. protected override object? DoGetValue(object target, string memberName)
  16. {
  17. return _propertyInfo.GetValue(target, index: null);
  18. }
  19. protected override void DoSetValue(object target, string memberName, object? value)
  20. {
  21. _propertyInfo.SetValue(target, value, index: null);
  22. }
  23. }