Пример #1
0
        public string Invoke(string baseUrl, object instance, Uri uri, NameValueCollection inputParameters)
        {
            FilterInputParameters(inputParameters);

            var type       = instance.GetType();
            var methodName = GetMethodNameFromUri(baseUrl, uri);

            ThrowIfMethodNameNotSpecified(methodName, instance, uri);
            ThrowIfMethodMissing(methodName, instance, uri);

            var method = type.GetMethod(methodName);

            ThrowIfParameterCountMismatches(method, type, uri, inputParameters);
            ThrowIfParameterMissing(method, type, uri, inputParameters);

            var values = GetParameterValues(inputParameters, method);
            var result = method.Invoke(instance, values);

            var serializedResult = _serializer.ToJson(result, new SerializationOptions {
                UseCamelCase = true
            });

            serializedResult = _jsonInterceptor.Intercept(serializedResult);

            return(serializedResult);
        }
Пример #2
0
        public string Invoke(string baseUrl, object instance, Uri uri, NameValueCollection inputParameters)
        {
            _logger.Trace($"BaseUrl : '{baseUrl}'");
            _logger.Trace($"Uri : '{uri}'");

            FilterInputParameters(inputParameters);

            var type       = instance.GetType();
            var methodName = GetMethodNameFromUri(baseUrl, uri);

            _logger.Trace($"Method : {methodName}");

            ThrowIfMethodNameNotSpecified(methodName, instance, uri);
            ThrowIfMethodMissing(methodName, instance, uri);

            var method = type.GetMethod(methodName);

            ThrowIfParameterCountMismatches(method, type, uri, inputParameters);
            ThrowIfParameterMissing(method, type, uri, inputParameters);

            var values = GetParameterValues(inputParameters, method);

            _logger.Trace($"Invoke with {values.Length} parameters");
            var result = method.Invoke(instance, values);

            var serializedResult = _serializer.ToJson(result, SerializationOptions.CamelCase);

            serializedResult = _jsonInterceptor.Intercept(serializedResult);

            return(serializedResult);
        }