Changeset 11872 for extensions/PiwigoLib/PiwigoLib/Proxy/Helper
- Timestamp:
- Aug 1, 2011, 5:47:03 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs
r11850 r11872 6 6 7 7 using Com.Piwigo.Lib.DTO.Helper; 8 using System.Xml; 9 using Com.Piwigo.Lib.DTO; 8 10 9 11 namespace Com.Piwigo.Lib.Proxy.Helper … … 11 13 internal static class PwgProxyReponseHelper 12 14 { 15 internal static void buildDicFieldFromArray<T>(List<T> values, String paramName, ref Dictionary<String, String> dcFields) 16 { 17 String FormatString = String.Empty; 18 String ParamValue = String.Empty; 19 20 Boolean firstOcc = true; 21 if (values != null) 22 { 23 foreach (T occurance in values) 24 { 25 if (firstOcc == true) 26 { 27 firstOcc = false; 28 FormatString = "{0}"; 29 } 30 else 31 { 32 FormatString = ",{0}"; 33 } 34 35 ParamValue += String.Format(FormatString,GetString(occurance)); 36 } 37 38 dcFields.Add(paramName, ParamValue); 39 } 40 } 41 42 internal static void buildDicFieldFromValue<T>(Nullable<T> nullableValue, String paramName, ref Dictionary<String, String> dcFields) where T : struct 43 { 44 if (nullableValue.HasValue) 45 { 46 buildDicFieldFromValue<T>(nullableValue.Value, paramName, ref dcFields); 47 } 48 } 49 50 internal static void buildDicFieldFromValue<T>(T value, String paramName, ref Dictionary<String, String> dcFields) 51 { 52 String FormatString = String.Empty; 53 String ParamValue = String.Empty; 54 55 FormatString = "{0}"; 56 57 ParamValue = GetString(value); 58 59 dcFields.Add(paramName, ParamValue); 60 } 61 13 62 internal static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) 14 63 { … … 31 80 foreach (T occurance in values) 32 81 { 33 queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode( occurance.ToString().ToLower()));82 queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(GetString(occurance))); 34 83 firstOcc = false; 35 84 } … … 38 87 } 39 88 40 internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) 41 where T: struct 89 internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) where T : struct 42 90 { 43 91 if (nullableValue.HasValue) … … 52 100 String ParamValue = String.Empty; 53 101 54 if (value != null)55 {56 102 FormatString = "{0}={1}"; 57 103 if (firstOcc != true) … … 60 106 } 61 107 62 if (typeof(T).IsEnum) 63 { 64 ParamValue = HttpUtility.UrlEncode(PwgEnumHelper<T>.StringValueOf(value)); 65 } 66 else 67 { 68 ParamValue = HttpUtility.UrlEncode(value.ToString().ToLower()); 69 } 108 ParamValue = HttpUtility.UrlEncode(GetString(value)); 70 109 71 110 queryStringBuilder.AppendFormat(FormatString, paramName, ParamValue); 72 111 73 112 firstOcc = false; 113 } 114 115 public static String GetString<T>(T value) 116 { 117 String strRet = String.Empty; 118 if (value is String) 119 { 120 strRet = (value as String); 74 121 } 122 else if (typeof(T).IsEnum) 123 { 124 strRet = PwgEnumHelper<T>.StringValueOf(value); 125 } 126 else if (value is PwgTag) 127 { 128 129 strRet = (value as PwgTag).Name; 130 } 131 else 132 { 133 134 strRet = (value as Object).ToString().ToLowerInvariant(); 135 } 136 137 return strRet; 75 138 } 76 139 }
Note: See TracChangeset
for help on using the changeset viewer.