Esempio n. 1
0
        private static void PopulateQueryStringWithParameters(QueryStringValues queryStringValues, object parameters)
        {
            if (parameters == null)
            {
                return;
            }

#if NET40
            var properties = parameters.GetType().GetProperties();
#else
            var properties = parameters.GetType().GetTypeInfo().DeclaredProperties;
#endif

            foreach (var property in properties)
            {
                var attribute = property.GetAttribute <QueryStringParameterAttribute>();
                var name      = attribute?.Key;
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }
                var value = property.GetValue(parameters, null);
                if (value == null)
                {
                    continue;
                }
                var valueText = value.ToString();
                queryStringValues.AddIfValueNotNullOrEmpty(name, valueText);
            }
        }
Esempio n. 2
0
        private static void PopulateQueryStringWithCustomValues(QueryStringValues queryStringValues, Dictionary <string, string> customValues)
        {
            if (customValues == null)
            {
                return;
            }

            if (customValues.Any(v => v.Key.Contains("[") || v.Key.Contains("]")))
            {
                throw new InvalidOperationException(
                          "The client does not support custom values with names containing the following chars: []");
            }

            foreach (var customValue in customValues)
            {
                queryStringValues.AddIfValueNotNullOrEmpty($"custom_values[{customValue.Key}]", customValue.Value);
            }
        }