Esempio n. 1
0
        static T GetPropertyCore <T>(JsiiPropertyAttribute propertyAttribute, Func <IClient, GetResponse> getFunc)
        {
            IServiceProvider serviceProvider = ServiceContainer.ServiceProvider;
            IClient          client          = serviceProvider.GetRequiredService <IClient>();

            GetResponse response = getFunc(client);

            IJsiiToFrameworkConverter converter    = serviceProvider.GetRequiredService <IJsiiToFrameworkConverter>();
            IReferenceMap             referenceMap = serviceProvider.GetRequiredService <IReferenceMap>();

            if (!converter.TryConvert(propertyAttribute, typeof(T), referenceMap, response.Value, out object frameworkValue))
            {
                throw new ArgumentException($"Could not convert value '{response.Value}' for property '{propertyAttribute.Name}'", nameof(getFunc));
            }

            return((T)frameworkValue);
        }
Esempio n. 2
0
        static T InvokeMethodCore <T>(
            JsiiMethodAttribute methodAttribute,
            object[] arguments,
            Func <IClient, object[], BeginResponse> beginFunc,
            Func <IClient, object[], InvokeResponse> invokeFunc
            )
        {
            IServiceProvider          serviceProvider = ServiceContainer.ServiceProvider;
            IClient                   client          = serviceProvider.GetRequiredService <IClient>();
            IJsiiToFrameworkConverter converter       = serviceProvider.GetRequiredService <IJsiiToFrameworkConverter>();
            IReferenceMap             referenceMap    = serviceProvider.GetRequiredService <IReferenceMap>();

            object result = GetResult();

            if (!converter.TryConvert(methodAttribute.Returns, typeof(T), referenceMap, result, out object frameworkValue))
            {
                throw new ArgumentException($"Could not convert result '{result}' for method '{methodAttribute.Name}'", nameof(result));
            }

            return((T)frameworkValue);

            object GetResult()
            {
                object[] args = ConvertArguments(methodAttribute.Parameters, arguments);

                if (methodAttribute.IsAsync)
                {
                    BeginResponse beginResponse = beginFunc(client, args);

                    InvokeCallbacks();

                    return(client.End(beginResponse.PromiseId).Result);
                }

                InvokeResponse invokeResponse = invokeFunc(client, args);

                return(invokeResponse.Result);
            }
        }