static CallbackResult InvokeMethod(InvokeRequest request, IReferenceMap referenceMap)
        {
            request = request ?? throw new ArgumentNullException(nameof(request));
            DeputyBase deputy = referenceMap.GetOrCreateNativeReference(request.ObjectReference);

            MethodInfo methodInfo = ReflectionUtils.GetNativeMethod(deputy.GetType(), request.Method);

            if (methodInfo == null)
            {
                throw new InvalidOperationException($"Received callback for {deputy.GetType().Name}.{request.Method} getter, but this method does not exist");
            }

            JsiiMethodAttribute attribute = methodInfo.GetCustomAttribute <JsiiMethodAttribute>();

            return(new CallbackResult(attribute?.Returns, methodInfo.Invoke(deputy, request.Arguments)));
        }
Exemple #2
0
        public static MethodInfo GetNativeMethod(Type classType, string name)
        {
            MethodInfo methodInfo = classType.GetMethods().FirstOrDefault(method =>
            {
                JsiiMethodAttribute attribute = method.GetCustomAttribute <JsiiMethodAttribute>();

                return(attribute != null && attribute.Name == name);
            });

            if (methodInfo == null)
            {
                throw new ArgumentNullException($"Class {classType.Name} does not have a method called {name}", nameof(name));
            }

            return(methodInfo);
        }