Fix handling of nullables

Improve error handling
This commit is contained in:
Flamefire committed 2014-10-24 23:08:15 +02:00
1 parent d7d6cba5ae
commit c3affed9b1
1 file changed
+7 -3
+7 -3
View File
@@ -173,7 +173,7 @@ namespace VocaluxeLib.Xml
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
Type subType = type.GetGenericArguments()[0]; Type subType = type.GetGenericArguments()[0];
return _GetPrimitiveValue(node, subType); return _GetValue(node, subType);
} }
object value = Activator.CreateInstance(type); object value = Activator.CreateInstance(type);
@@ -189,9 +189,13 @@ namespace VocaluxeLib.Xml
{ {
value = Convert.ChangeType(node.InnerText, type, CultureInfo.InvariantCulture); value = Convert.ChangeType(node.InnerText, type, CultureInfo.InvariantCulture);
} }
catch (FormatException) catch (FormatException e)
{ {
throw new XmlException("Invalid format in " + _FindXPath(node) + ": '" + node.InnerText + "'"); throw new XmlException("Invalid format in " + _FindXPath(node) + ": '" + node.InnerText + "' (" + e.Message + ")");
}
catch (InvalidCastException e)
{
throw new XmlException(e.Message + " in " + _FindXPath(node) + ": '" + node.InnerText + "'");
} }
return value; return value;
} }