source: extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs @ 3834

Last change on this file since 3834 was 3834, checked in by bayral, 15 years ago

start with pwg.catgeroies.* support

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Web;
6
7namespace Com.Piwigo.Lib.Proxy.Helper
8{
9    public static class PwgProxyReponseHelper
10    {
11        public static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
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            }
36        }
37
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            }
45        }
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        }
62    }
63}
Note: See TracBrowser for help on using the repository browser.