Files
mono/mcs/class/System.Web.Services/System.Web.Services.Protocols/ValueCollectionParameterReader.cs
T
Lluis Sanchez 3ff5b4d210 * HttpWebClientProtocol.cs: Added missing property.
* Methods.cs: Default binding for a method must be null.
	* SoapHeaderDirection.cs: Added missing enum value.
	* SoapMessage.cs: Added missing property.
	* TypeStubManager.cs: Removed unneded check from AddBinding.
	  In GetBinding(), return default binding if name is null.
	* ValueCollectionParameterReader.cs: IsPrimitive must be internal.

svn path=/trunk/mcs/; revision=22455
2004-01-24 01:52:48 +00:00

93 lines
2.4 KiB
C#

//
// System.Web.Services.Protocols.ValueCollectionParameterReader.cs
//
// Author:
// Tim Coleman ([email protected])
// Lluis Sanchez Gual ([email protected])
//
// Copyright (C) Tim Coleman, 2002
//
using System.Collections.Specialized;
using System.Reflection;
using System.Web;
using System.Xml;
namespace System.Web.Services.Protocols {
public abstract class ValueCollectionParameterReader : MimeParameterReader {
ParameterInfo[] parameters;
#region Constructors
protected ValueCollectionParameterReader ()
{
}
#endregion // Constructors
#region Methods
public override object GetInitializer (LogicalMethodInfo methodInfo)
{
if (IsSupported (methodInfo)) return methodInfo.Parameters;
else return null;
}
public override void Initialize (object o)
{
parameters = (ParameterInfo[]) o;
}
public static bool IsSupported (LogicalMethodInfo methodInfo)
{
foreach (ParameterInfo param in methodInfo.Parameters)
if (!IsSupported (param)) return false;
return true;
}
public static bool IsSupported (ParameterInfo paramInfo)
{
Type type = paramInfo.ParameterType;
if (type.IsByRef || paramInfo.IsOut) return false;
if (type.IsArray) return IsSupportedPrimitive (type.GetElementType());
else return IsSupportedPrimitive (type);
}
internal static bool IsSupportedPrimitive (Type type)
{
return ( type.IsPrimitive ||
type == typeof(string) ||
type == typeof(DateTime) ||
type == typeof(Guid) ||
type == typeof(XmlQualifiedName) ||
type == typeof(TimeSpan) ||
type == typeof(byte[])
);
}
protected object[] Read (NameValueCollection collection)
{
object[] res = new object [parameters.Length];
for (int n=0; n<res.Length; n++)
{
string val = collection [parameters[n].Name];
if (val == null) throw new InvalidOperationException ("Missing parameter: " + parameters[n].Name);
try
{
res [n] = Convert.ChangeType (val, parameters[n].ParameterType);
}
catch (Exception ex)
{
string error = "Cannot convert " + val + " to " + parameters[n].ParameterType.FullName + "\n";
error += "Parameter name: " + parameters[n].Name + " --> " + ex.Message;
throw new InvalidOperationException (error);
}
}
return res;
}
#endregion // Methods
}
}