Пример #1
0
 /// <include file='doc\ValueCollectionParameterReader.uex' path='docs/doc[@for="ValueCollectionParameterReader.Read"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 protected object[] Read(NameValueCollection collection)
 {
     object[] parameters = new object[paramInfos.Length];
     for (int i = 0; i < paramInfos.Length; i++)
     {
         ParameterInfo paramInfo = paramInfos[i];
         if (paramInfo.ParameterType.IsArray)
         {
             string[] arrayValues = collection.GetValues(paramInfo.Name);
             Type     arrayType   = paramInfo.ParameterType.GetElementType();
             Array    array       = Array.CreateInstance(arrayType, arrayValues.Length);
             for (int j = 0; j < arrayValues.Length; j++)
             {
                 string value = arrayValues[j];
                 array.SetValue(ScalarFormatter.FromString(value, arrayType), j);
             }
             parameters[i] = array;
         }
         else
         {
             string value = collection[paramInfo.Name];
             if (value == null)
             {
                 throw new InvalidOperationException(Res.GetString(Res.WebMissingParameter, paramInfo.Name));
             }
             parameters[i] = ScalarFormatter.FromString(value, paramInfo.ParameterType);
         }
     }
     return(parameters);
 }
 protected object[] Read(NameValueCollection collection)
 {
     object[] objArray = new object[this.paramInfos.Length];
     for (int i = 0; i < this.paramInfos.Length; i++)
     {
         ParameterInfo info = this.paramInfos[i];
         if (info.ParameterType.IsArray)
         {
             string[] values      = collection.GetValues(info.Name);
             Type     elementType = info.ParameterType.GetElementType();
             Array    array       = Array.CreateInstance(elementType, values.Length);
             for (int j = 0; j < values.Length; j++)
             {
                 string str = values[j];
                 array.SetValue(ScalarFormatter.FromString(str, elementType), j);
             }
             objArray[i] = array;
         }
         else
         {
             string str2 = collection[info.Name];
             if (str2 == null)
             {
                 throw new InvalidOperationException(Res.GetString("WebMissingParameter", new object[] { info.Name }));
             }
             objArray[i] = ScalarFormatter.FromString(str2, info.ParameterType);
         }
     }
     return(objArray);
 }