public object ReadObject(Type type)
{
if (serialized_object_count++ == serializer.MaxItemsInObjectGraph)
{
throw SerializationError(String.Format("The object graph exceeded the maximum object count '{0}' specified in the serializer", serializer.MaxItemsInObjectGraph));
}
switch (Type.GetTypeCode(type))
{
case TypeCode.DBNull:
string dbn = reader.ReadElementContentAsString();
if (dbn != String.Empty)
{
throw new SerializationException(String.Format("The only expected DBNull value string is '{{}}'. Tha actual input was '{0}'.", dbn));
}
return(DBNull.Value);
case TypeCode.String:
return(reader.ReadElementContentAsString());
case TypeCode.Single:
return(reader.ReadElementContentAsFloat());
case TypeCode.Double:
return(reader.ReadElementContentAsDouble());
case TypeCode.Decimal:
return(reader.ReadElementContentAsDecimal());
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.UInt16:
case TypeCode.UInt32:
int i = reader.ReadElementContentAsInt();
if (type.IsEnum)
{
return(Enum.ToObject(type, (object)i));
}
else
{
return(Convert.ChangeType(i, type, null));
}
case TypeCode.Int64:
case TypeCode.UInt64:
long l = reader.ReadElementContentAsLong();
if (type.IsEnum)
{
return(Enum.ToObject(type, (object)l));
}
else
{
return(Convert.ChangeType(l, type, null));
}
case TypeCode.Boolean:
return(reader.ReadElementContentAsBoolean());
default:
if (type == typeof(Guid))
{
return(new Guid(reader.ReadElementContentAsString()));
}
else if (type == typeof(Uri))
{
return(new Uri(reader.ReadElementContentAsString()));
}
else if (type == typeof(XmlQualifiedName))
{
string s = reader.ReadElementContentAsString();
int idx = s.IndexOf(':');
return(idx < 0 ? new XmlQualifiedName(s) : new XmlQualifiedName(s.Substring(0, idx), s.Substring(idx + 1)));
}
else if (type != typeof(object))
{
// strongly-typed object
if (reader.IsEmptyElement)
{
// empty -> null array or object
reader.Read();
return(null);
}
Type ct = GetCollectionType(type);
if (ct != null)
{
return(DeserializeGenericCollection(type, ct));
}
else
{
TypeMap map = GetTypeMap(type);
return(map.Deserialize(this));
}
}
else
{
return(ReadInstanceDrivenObject());
}
}
}