-Added line number information to deserialization errors

-Added BinaryReader/BinaryWriter constructor overloads to BsonReader/BsonWriter
This commit is contained in:
JamesNK
2012-01-19 05:48:24 +00:00
parent b146481c87
commit a9e100e0a7
19 changed files with 260 additions and 176 deletions
+41
View File
@@ -450,5 +450,46 @@ namespace Newtonsoft.Json
_token = JsonToken.None;
_value = null;
}
internal JsonReaderException CreateReaderException(JsonReader reader, string message)
{
return CreateReaderException(reader, message, null);
}
internal JsonReaderException CreateReaderException(JsonReader reader, string message, Exception ex)
{
return CreateReaderException(reader as IJsonLineInfo, message, ex);
}
internal JsonReaderException CreateReaderException(IJsonLineInfo lineInfo, string message, Exception ex)
{
message = FormatExceptionMessage(lineInfo, message);
int lineNumber;
int linePosition;
if (lineInfo != null)
{
lineNumber = lineInfo.LineNumber;
linePosition = lineInfo.LinePosition;
}
else
{
lineNumber = 0;
linePosition = 0;
}
return new JsonReaderException(message, ex, lineNumber, linePosition);
}
internal static string FormatExceptionMessage(IJsonLineInfo lineInfo, string message)
{
if (!message.EndsWith("."))
message += ".";
if (lineInfo != null)
message += " Line {0}, position {1}.".FormatWith(CultureInfo.InvariantCulture, lineInfo.LineNumber, lineInfo.LinePosition);
return message;
}
}
}