string.AddQueryParam(string, object)

Here are the examples of the csharp api class string.AddQueryParam(string, object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Example 7

1. Example

Project: PinSharp
Source File: PathBuilder.cs
View license
public static string BuildPath(string basePath, RequestOptions options)
        {
            var path = basePath;

            if (!path.EndsWith("/"))
                path += "/";

            if (options?.SearchQuery != null)
                path = path.AddQueryParam("query", options.SearchQuery);

            if (options?.Fields?.Any() == true)
            {
                var fields = string.Join(",", options.Fields);
                path = path.AddQueryParam("fields", fields);
            }

            if (options?.Cursor != null)
                path = path.AddQueryParam("cursor", options.Cursor);

            if (options?.Limit > 0)
                path = path.AddQueryParam("limit", options.Limit);

            if (options?.CustomData != null)
            {
                foreach (var prop in options.CustomData.GetType().GetProperties())
                {
                    var value = prop.GetValue(options.CustomData);
                    if (value == null)
                        continue;
                    if (value is int && (int) value == 0)
                        continue;

                    var key = prop.Name.ToLower();
                    path = path.AddQueryParam(key, value);
                }
            }

            return path;
        }