1 | #region License
|
---|
2 | /*---------------------------------------------------------------------------------*\
|
---|
3 |
|
---|
4 | Distributed under the terms of an MIT-style license:
|
---|
5 |
|
---|
6 | The MIT License
|
---|
7 |
|
---|
8 | Copyright (c) 2006-2009 Stephen M. McKamey
|
---|
9 |
|
---|
10 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
11 | of this software and associated documentation files (the "Software"), to deal
|
---|
12 | in the Software without restriction, including without limitation the rights
|
---|
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | copies of the Software, and to permit persons to whom the Software is
|
---|
15 | furnished to do so, subject to the following conditions:
|
---|
16 |
|
---|
17 | The above copyright notice and this permission notice shall be included in
|
---|
18 | all copies or substantial portions of the Software.
|
---|
19 |
|
---|
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
26 | THE SOFTWARE.
|
---|
27 |
|
---|
28 | \*---------------------------------------------------------------------------------*/
|
---|
29 | #endregion License
|
---|
30 |
|
---|
31 | using System;
|
---|
32 |
|
---|
33 | namespace JsonFx.Json
|
---|
34 | {
|
---|
35 | public class JsonSerializationException : InvalidOperationException
|
---|
36 | {
|
---|
37 | #region Init
|
---|
38 |
|
---|
39 | public JsonSerializationException() : base() { }
|
---|
40 |
|
---|
41 | public JsonSerializationException(string message) : base(message) { }
|
---|
42 |
|
---|
43 | public JsonSerializationException(string message, Exception innerException) : base(message, innerException) { }
|
---|
44 |
|
---|
45 | public JsonSerializationException(
|
---|
46 | System.Runtime.Serialization.SerializationInfo info,
|
---|
47 | System.Runtime.Serialization.StreamingContext context)
|
---|
48 | : base(info, context)
|
---|
49 | {
|
---|
50 | }
|
---|
51 |
|
---|
52 | #endregion Init
|
---|
53 | }
|
---|
54 |
|
---|
55 | public class JsonDeserializationException : JsonSerializationException
|
---|
56 | {
|
---|
57 | #region Fields
|
---|
58 |
|
---|
59 | private int index = -1;
|
---|
60 |
|
---|
61 | #endregion Fields
|
---|
62 |
|
---|
63 | #region Init
|
---|
64 |
|
---|
65 | public JsonDeserializationException(string message, int index) : base(message)
|
---|
66 | {
|
---|
67 | this.index = index;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public JsonDeserializationException(string message, Exception innerException, int index)
|
---|
71 | : base(message, innerException)
|
---|
72 | {
|
---|
73 | this.index = index;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public JsonDeserializationException(
|
---|
77 | System.Runtime.Serialization.SerializationInfo info,
|
---|
78 | System.Runtime.Serialization.StreamingContext context)
|
---|
79 | : base(info, context)
|
---|
80 | {
|
---|
81 | }
|
---|
82 |
|
---|
83 | #endregion Init
|
---|
84 |
|
---|
85 | #region Properties
|
---|
86 |
|
---|
87 | /// <summary>
|
---|
88 | /// Gets the character position in the stream where the error occurred.
|
---|
89 | /// </summary>
|
---|
90 | public int Index
|
---|
91 | {
|
---|
92 | get { return this.index; }
|
---|
93 | }
|
---|
94 |
|
---|
95 | #endregion Properties
|
---|
96 |
|
---|
97 | #region Methods
|
---|
98 |
|
---|
99 | /// <summary>
|
---|
100 | /// Helper method which converts the index into Line and Column numbers
|
---|
101 | /// </summary>
|
---|
102 | /// <param name="source"></param>
|
---|
103 | /// <param name="line"></param>
|
---|
104 | /// <param name="col"></param>
|
---|
105 | public void GetLineAndColumn(string source, out int line, out int col)
|
---|
106 | {
|
---|
107 | if (source == null)
|
---|
108 | {
|
---|
109 | throw new ArgumentNullException();
|
---|
110 | }
|
---|
111 |
|
---|
112 | col = 1;
|
---|
113 | line = 1;
|
---|
114 |
|
---|
115 | bool foundLF = false;
|
---|
116 | int i = Math.Min(this.index, source.Length);
|
---|
117 | for (; i>0; i--)
|
---|
118 | {
|
---|
119 | if (!foundLF)
|
---|
120 | {
|
---|
121 | col++;
|
---|
122 | }
|
---|
123 | if (source[i-1] == '\n')
|
---|
124 | {
|
---|
125 | line++;
|
---|
126 | foundLF = true;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | #endregion Methods
|
---|
132 | }
|
---|
133 |
|
---|
134 | public class JsonTypeCoersionException : ArgumentException
|
---|
135 | {
|
---|
136 | #region Init
|
---|
137 |
|
---|
138 | public JsonTypeCoersionException() : base() { }
|
---|
139 |
|
---|
140 | public JsonTypeCoersionException(string message) : base(message) { }
|
---|
141 |
|
---|
142 | public JsonTypeCoersionException(string message, Exception innerException) : base(message, innerException) { }
|
---|
143 |
|
---|
144 | public JsonTypeCoersionException(
|
---|
145 | System.Runtime.Serialization.SerializationInfo info,
|
---|
146 | System.Runtime.Serialization.StreamingContext context)
|
---|
147 | : base(info, context)
|
---|
148 | {
|
---|
149 | }
|
---|
150 |
|
---|
151 | #endregion Init
|
---|
152 | }
|
---|
153 | }
|
---|