public static XmlRpcType GetXmlRpcType(Type t)
{
XmlRpcType ret;
if (t == typeof(Int32))
ret = XmlRpcType.tInt32;
else if (t == typeof(XmlRpcInt))
ret = XmlRpcType.tInt32;
else if (t == typeof(Boolean))
ret = XmlRpcType.tBoolean;
else if (t == typeof(XmlRpcBoolean))
ret = XmlRpcType.tBoolean;
else if (t == typeof(String))
ret = XmlRpcType.tString;
else if (t == typeof(Double))
ret = XmlRpcType.tDouble;
else if (t == typeof(XmlRpcDouble))
ret = XmlRpcType.tDouble;
else if (t == typeof(DateTime))
ret = XmlRpcType.tDateTime;
else if (t == typeof(XmlRpcDateTime))
ret = XmlRpcType.tDateTime;
else if (t == typeof(byte[]))
ret = XmlRpcType.tBase64;
else if (t == typeof(XmlRpcStruct))
{
ret = XmlRpcType.tHashtable;
}
else if (t == typeof(Array))
ret = XmlRpcType.tArray;
else if (t.IsArray)
{
#if (!COMPACT_FRAMEWORK)
Type elemType = t.GetElementType();
if (elemType != typeof(Object)
&& GetXmlRpcType(elemType) == XmlRpcType.tInvalid)
{
ret = XmlRpcType.tInvalid;
}
else
{
if (t.GetArrayRank() == 1) // single dim array
ret = XmlRpcType.tArray;
else
ret = XmlRpcType.tMultiDimArray;
}
#else
//!! check types of array elements if not Object[]
Type elemType = null;
string[] checkSingleDim = Regex.Split(t.FullName, "\\[\\]$");
if (checkSingleDim.Length > 1) // single dim array
{
elemType = Type.GetType(checkSingleDim[0]);
ret = XmlRpcType.tArray;
}
else
{
string[] checkMultiDim = Regex.Split(t.FullName, "\\[,[,]*\\]$");
if (checkMultiDim.Length > 1)
{
elemType = Type.GetType(checkMultiDim[0]);
ret = XmlRpcType.tMultiDimArray;
}
else
ret = XmlRpcType.tInvalid;
}
if (elemType != null)
{
if (elemType != typeof(Object)
&& GetXmlRpcType(elemType) == XmlRpcType.tInvalid)
{
ret = XmlRpcType.tInvalid;
}
}
#endif
}
#if !FX1_0
else if (t == typeof(int?))
ret = XmlRpcType.tInt32;
else if (t == typeof(Boolean?))
ret = XmlRpcType.tBoolean;
else if (t == typeof(Double?))
ret = XmlRpcType.tDouble;
else if (t == typeof(DateTime?))
ret = XmlRpcType.tDateTime;
#endif
else if (t == typeof(void))
{
ret = XmlRpcType.tVoid;
}
else if ((t.IsValueType && !t.IsPrimitive && !t.IsEnum)
|| t.IsClass)
{
// if type is struct or class its only valid for XML-RPC mapping if all
// its members have a valid mapping or are of type object which
// maps to any XML-RPC type
MemberInfo[] mis = t.GetMembers();
foreach (MemberInfo mi in mis)
{
if (mi.MemberType == MemberTypes.Field)
{
FieldInfo fi = (FieldInfo)mi;
if (fi.FieldType != typeof(Object)
&& GetXmlRpcType(fi.FieldType) == XmlRpcType.tInvalid)
{
return XmlRpcType.tInvalid;
}
}
else if (mi.MemberType == MemberTypes.Property)
{
PropertyInfo pi = (PropertyInfo)mi;
if (pi.PropertyType != typeof(Object)
&& GetXmlRpcType(pi.PropertyType) == XmlRpcType.tInvalid)
{
return XmlRpcType.tInvalid;
}
}
}
ret = XmlRpcType.tStruct;
}
else
ret = XmlRpcType.tInvalid;
return ret;
}