MethodAccessor.cs 988 B

123456789101112131415161718192021222324252627282930
  1. using Jint.Runtime.Descriptors;
  2. namespace Jint.Runtime.Interop.Reflection
  3. {
  4. internal sealed class MethodAccessor : ReflectionAccessor
  5. {
  6. private readonly Type _targetType;
  7. private readonly string _name;
  8. private readonly MethodDescriptor[] _methods;
  9. public MethodAccessor(Type targetType, string name, MethodDescriptor[] methods)
  10. : base(null!, name)
  11. {
  12. _targetType = targetType;
  13. _name = name;
  14. _methods = methods;
  15. }
  16. public override bool Writable => false;
  17. protected override object? DoGetValue(object target) => null;
  18. protected override void DoSetValue(object target, object? value) { }
  19. public override PropertyDescriptor CreatePropertyDescriptor(Engine engine, object target, bool enumerable = true)
  20. {
  21. return new(new MethodInfoFunction(engine, _targetType, target, _name, _methods), PropertyFlag.AllForbidden);
  22. }
  23. }
  24. }