PropertyAccessor.cs 856 B

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