[3827] | 1 | using System; |
---|
| 2 | using System.Collections.Generic; |
---|
| 3 | using System.Linq; |
---|
| 4 | using System.Text; |
---|
| 5 | using System.Web; |
---|
| 6 | |
---|
| 7 | namespace Com.Piwigo.Lib.Proxy.Helper |
---|
| 8 | { |
---|
[3834] | 9 | public static class PwgProxyReponseHelper |
---|
[3827] | 10 | { |
---|
[3834] | 11 | public static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) |
---|
[3827] | 12 | { |
---|
| 13 | String FormatString = String.Empty; |
---|
| 14 | if (values != null) |
---|
| 15 | { |
---|
| 16 | if (values.Count == 1) |
---|
| 17 | { |
---|
| 18 | FormatString = "{0}={1}"; |
---|
| 19 | } |
---|
| 20 | else |
---|
| 21 | { |
---|
| 22 | FormatString = "{0}[]={1}"; |
---|
| 23 | } |
---|
| 24 | if (firstOcc != true) |
---|
| 25 | { |
---|
| 26 | FormatString = String.Format("&{0}", FormatString); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | foreach (T occurance in values) |
---|
| 30 | { |
---|
| 31 | queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(occurance.ToString().ToLower())); |
---|
| 32 | firstOcc = false; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | } |
---|
[3834] | 36 | } |
---|
[3827] | 37 | |
---|
[3834] | 38 | public static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) |
---|
| 39 | where T: struct |
---|
| 40 | { |
---|
| 41 | if (nullableValue.HasValue) |
---|
| 42 | { |
---|
| 43 | buildQueryFromValue<T>(nullableValue.Value, paramName, ref firstOcc, queryStringBuilder); |
---|
| 44 | } |
---|
[3827] | 45 | } |
---|
[3834] | 46 | |
---|
| 47 | public static void buildQueryFromValue<T>(T value, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) |
---|
| 48 | { |
---|
| 49 | String FormatString = String.Empty; |
---|
| 50 | if (value != null) |
---|
| 51 | { |
---|
| 52 | FormatString = "{0}={1}"; |
---|
| 53 | if (firstOcc != true) |
---|
| 54 | { |
---|
| 55 | FormatString = String.Format("&{0}", FormatString); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(value.ToString().ToLower())); |
---|
| 59 | firstOcc = false; |
---|
| 60 | } |
---|
| 61 | } |
---|
[3827] | 62 | } |
---|
| 63 | } |
---|