C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
RequestParameters.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using RestSharp;
5
7{
9 public class RequestParameters : List<Parameter>
10 {
13 public RequestParameters(IEnumerable<Parameter> parameters = null)
14 {
15 if (parameters != null)
16 AddRange(parameters);
17 }
18
23 [Obsolete("AddQueryParameter is now used to add a query (url) parameter. " +
24 "The old behaviour of adding a ParameterType.GetOrPost parameter by default let to " +
25 "unexpected behaviour at POST time. If you truly wish to use a GetOrPost parameter, " +
26 "you may do so by using one of the explicit AddParameter overloads.")]
27 public RequestParameters AddGetParameter(string name, string value) => AddQueryParameter(name, value);
28
36 public RequestParameters AddQueryParameter(string name, string value)
37 {
38 return String.IsNullOrEmpty(value) ? this :
39 AddParameter(name, value, ParameterType.QueryString);
40 }
41
46 public RequestParameters AddHeader(string name, string value = null)
47 {
48 return AddParameter(name, value, ParameterType.HttpHeader);
49 }
50
54 public RequestParameters AddParameter(Parameter parameter)
55 {
56 if (parameter == null)
57 throw new NullReferenceException(nameof(parameter));
58 Add(parameter);
59 return this;
60 }
61
69 public RequestParameters AddParameter(string name, object value, ParameterType type,
70 string contentType = null)
71 {
72 Add(new Parameter { Name = name, Value = value, Type = type, ContentType = contentType });
73 return this;
74 }
75
79 public RequestParameters AddParameters(IEnumerable<Parameter> collection)
80 {
81 if (collection != null)
82 AddRange(collection);
83 return this;
84 }
85
91 public string GetHashString()
92 {
93 return String.Join("&", this.OrderBy(p => p.Name)
94 .Select(p => $"{p.Name}={p.Value}"));
95 }
96 }
97}
Helper class which makes it easier to build a set of request parameters.
string GetHashString()
Creates and returns a serialized list of all parameters currently in this list sorted by parameter na...
RequestParameters AddParameter(Parameter parameter)
Adds the specified parameter to this list and returns the list.
RequestParameters AddParameter(string name, object value, ParameterType type, string contentType=null)
Adds a new parameter with the specified properties to this list and returns the list.
RequestParameters AddHeader(string name, string value=null)
Adds the specified name/value pair as a HEADER.
RequestParameters AddQueryParameter(string name, string value)
Adds the specified name/value pair as a new request parameter with the type ParameterType....
RequestParameters AddGetParameter(string name, string value)
An obsolete alias for AddQueryParameter. Adds a new request parameter with the type ParameterType....
RequestParameters(IEnumerable< Parameter > parameters=null)
Build a set of request parameters.
RequestParameters AddParameters(IEnumerable< Parameter > collection)
Adds the specified parameters to this list and returns the list.