Skip to content

Commit

Permalink
Add .Data[] keys on DeserializationException for easy access.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Craver committed May 3, 2016
1 parent 2398423 commit 58f9a23
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Jil/DeserializationException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Jil.Deserialize;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jil
{
Expand All @@ -13,29 +10,45 @@ namespace Jil
/// </summary>
public class DeserializationException : Exception
{
private long? _position;
private string _snippetAfterError;
private bool _endedUnexpectedly;

/// <summary>
/// The position in the TextReader where an error occurred, if it is available.
///
/// This is meant for debugging purposes only, as exactly when Jil decides to abandon deserialization
/// and throw an exception is an implementation detail.
/// </summary>
public long? Position { get; private set; }
public long? Position
{
get { return _position; }
private set { Data["Jil-Position"] = _position = value; }
}

/// <summary>
/// A snippet of text immediately after an error occurred.
///
/// This is meant for debugging purposes only, as exactly when Jil decides to abandon deserialization
/// and throw an exception is an implementation detail.
/// </summary>
public string SnippetAfterError { get; private set; }
public string SnippetAfterError
{
get { return _snippetAfterError; }
private set { Data["Jil-SnippetAfterError"] = _snippetAfterError = value; }
}

/// <summary>
/// Whether or not the TextReader ended sooner than Jil expected.
///
/// This is meant for debugging purposes only, as exactly when Jil decides to abandon deserialization
/// and throw an exception is an implementation detail.
/// </summary>
public bool EndedUnexpectedly { get; private set; }
public bool EndedUnexpectedly
{
get { return _endedUnexpectedly; }
private set { Data["Jil-EndedUnexpectedly"] = _endedUnexpectedly = value; }
}

internal DeserializationException(Exception inner, TextReader reader, bool endedEarly)
: base(inner.Message, inner)
Expand Down

0 comments on commit 58f9a23

Please sign in to comment.