Exemple #1
0
 /// <summary>
 /// Converts the request to response.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="converter">The converter.</param>
 /// <returns>The response.</returns>
 protected virtual TResponse Convert(TRequest request, IConvertible <TNode, TResponse> converter)
 {
     try
     {
         if (!IsValid(request))
         {
             throw new ArgumentException(nameof(request));
         }
         return(converter.Convert(InstantiateRootNodeFromRequest(request)));
     }
     catch (Exception exc)
     {
         if (_throwOnError)
         {
             throw;
         }
         return(GetErrorResponse(exc));
     }
 }
        /// <inheritdoc/>
        public object?Convert(object?value)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is object[] array)
            {
                var result = new HashSet <T>();

                foreach (var item in array)
                {
                    result.Add((T)_convertible.Convert(item) !);
                }

                return(result);
            }

            throw new ArgumentException("Invalid value", nameof(value));
        }
Exemple #3
0
        /// <inheritdoc/>
        public object?Convert(object?value)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is object[] array)
            {
                var result = new T[array.Length];

                for (var i = 0; i < array.Length; i++)
                {
                    result[i] = (T)_convertible.Convert(array[i]) !;
                }

                return(result);
            }

            throw new ArgumentException("Invalid value", nameof(value));
        }