diff --git a/README.md b/README.md
old mode 100755
new mode 100644
index 31e7c75..4be156a
--- a/README.md
+++ b/README.md
@@ -65,4 +65,3 @@ C# ASP .NET sample application which demonstrates integration with Worldpay API.
- Also in Web.config, set OrderLog to a location on your server which has read/write access permissions for your web server. In IIS on Windows, this usually means granting access to IUSR and IIS_IUSRS via the Windows Explorer folder properties dialog.
- Visual Studio users can now be able to run the application simply by opening the page 'CreateOrder.aspx' and clicking the 'run' button from the toolbar.
- To test credit card transactions via the IDE, simply fill out the details on the page and submit.
-
diff --git a/Release.24.1.2017.zip b/Release.24.1.2017.zip
new file mode 100755
index 0000000..cf65a66
Binary files /dev/null and b/Release.24.1.2017.zip differ
diff --git a/worldpay-lib-dotnet-2-0/.gitignore b/worldpay-lib-dotnet-2-0/.gitignore
old mode 100755
new mode 100644
index f4ecdc5..a879798
--- a/worldpay-lib-dotnet-2-0/.gitignore
+++ b/worldpay-lib-dotnet-2-0/.gitignore
@@ -1,4 +1,4 @@
-TestResults
-obj
-*.suo
+TestResults
+obj
+*.suo
*.user
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/HtmlColorConverter.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/HtmlColorConverter.cs
old mode 100755
new mode 100644
index 71c09fa..3027b12
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/HtmlColorConverter.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/HtmlColorConverter.cs
@@ -1,71 +1,71 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Drawing;
-
-namespace Newtonsoft.Json.Converters
-{
- ///
- /// Converts a object to and from JSON.
- ///
- public class HtmlColorConverter : JsonConverter
- {
- ///
- /// Writes the JSON representation of the object.
- ///
- /// The to write to.
- /// The value.
- public override void WriteJson(JsonWriter writer, object value)
- {
- writer.WriteValue(ColorTranslator.ToHtml((Color)value));
- }
-
- ///
- /// Determines whether this instance can convert the specified value type.
- ///
- /// Type of the value.
- ///
- /// true if this instance can convert the specified value type; otherwise, false.
- ///
- public override bool CanConvert(Type valueType)
- {
- return typeof(Color).IsAssignableFrom(valueType);
- }
-
- ///
- /// Reads the JSON representation of the object.
- ///
- /// The to read from.
- /// Type of the object.
- /// The object value.
- public override object ReadJson(JsonReader reader, Type objectType)
- {
- throw new NotImplementedException();
- }
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a object to and from JSON.
+ ///
+ public class HtmlColorConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ public override void WriteJson(JsonWriter writer, object value)
+ {
+ writer.WriteValue(ColorTranslator.ToHtml((Color)value));
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified value type.
+ ///
+ /// Type of the value.
+ ///
+ /// true if this instance can convert the specified value type; otherwise, false.
+ ///
+ public override bool CanConvert(Type valueType)
+ {
+ return typeof(Color).IsAssignableFrom(valueType);
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
+ public override object ReadJson(JsonReader reader, Type objectType)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
old mode 100755
new mode 100644
index dad4e0d..9786612
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
@@ -1,90 +1,90 @@
-using System;
-using System.Globalization;
-using Newtonsoft.Json.Utilities;
-
-namespace Newtonsoft.Json.Converters
-{
- ///
- /// Converts a to and from the ISO 8601 date format (e.g. 2008-04-12T12:53Z).
- ///
- public class IsoDateTimeConverter : JsonConverter
- {
- private const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
-
- private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
-
- ///
- /// Gets or sets the date time styles used when converting a date to and from JSON.
- ///
- /// The date time styles used when converting a date to and from JSON.
- public DateTimeStyles DateTimeStyles
- {
- get { return _dateTimeStyles; }
- set { _dateTimeStyles = value; }
- }
-
- ///
- /// Writes the JSON representation of the object.
- ///
- /// The to write to.
- /// The value.
- public override void WriteJson(JsonWriter writer, object value)
- {
- string text;
-
- if (value is DateTime)
- {
- DateTime dateTime = (DateTime)value;
-
- if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
- || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
- dateTime = dateTime.ToUniversalTime();
-
- text = dateTime.ToString(DateTimeFormat, CultureInfo.InvariantCulture);
- }
- else
- {
- DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
- if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
- || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
- dateTimeOffset = dateTimeOffset.ToUniversalTime();
-
- text = dateTimeOffset.ToString(DateTimeFormat, CultureInfo.InvariantCulture);
- }
-
- writer.WriteValue(text);
- }
-
- ///
- /// Reads the JSON representation of the object.
- ///
- /// The to read from.
- /// Type of the object.
- /// The object value.
- public override object ReadJson(JsonReader reader, Type objectType)
- {
- if (reader.TokenType != JsonToken.String)
- throw new Exception("Unexpected token parsing date. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
-
- string dateText = reader.Value.ToString();
-
- if (objectType == typeof(DateTimeOffset))
- return DateTimeOffset.Parse(dateText, CultureInfo.InvariantCulture, _dateTimeStyles);
-
- return DateTime.Parse(dateText, CultureInfo.InvariantCulture, _dateTimeStyles);
- }
-
- ///
- /// Determines whether this instance can convert the specified object type.
- ///
- /// Type of the object.
- ///
- /// true if this instance can convert the specified object type; otherwise, false.
- ///
- public override bool CanConvert(Type objectType)
- {
- return (typeof(DateTime).IsAssignableFrom(objectType)
- || typeof(DateTimeOffset).IsAssignableFrom(objectType));
- }
- }
+using System;
+using System.Globalization;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a to and from the ISO 8601 date format (e.g. 2008-04-12T12:53Z).
+ ///
+ public class IsoDateTimeConverter : JsonConverter
+ {
+ private const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
+
+ private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
+
+ ///
+ /// Gets or sets the date time styles used when converting a date to and from JSON.
+ ///
+ /// The date time styles used when converting a date to and from JSON.
+ public DateTimeStyles DateTimeStyles
+ {
+ get { return _dateTimeStyles; }
+ set { _dateTimeStyles = value; }
+ }
+
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ public override void WriteJson(JsonWriter writer, object value)
+ {
+ string text;
+
+ if (value is DateTime)
+ {
+ DateTime dateTime = (DateTime)value;
+
+ if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
+ || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
+ dateTime = dateTime.ToUniversalTime();
+
+ text = dateTime.ToString(DateTimeFormat, CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
+ if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
+ || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
+ dateTimeOffset = dateTimeOffset.ToUniversalTime();
+
+ text = dateTimeOffset.ToString(DateTimeFormat, CultureInfo.InvariantCulture);
+ }
+
+ writer.WriteValue(text);
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
+ public override object ReadJson(JsonReader reader, Type objectType)
+ {
+ if (reader.TokenType != JsonToken.String)
+ throw new Exception("Unexpected token parsing date. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+
+ string dateText = reader.Value.ToString();
+
+ if (objectType == typeof(DateTimeOffset))
+ return DateTimeOffset.Parse(dateText, CultureInfo.InvariantCulture, _dateTimeStyles);
+
+ return DateTime.Parse(dateText, CultureInfo.InvariantCulture, _dateTimeStyles);
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+ return (typeof(DateTime).IsAssignableFrom(objectType)
+ || typeof(DateTimeOffset).IsAssignableFrom(objectType));
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
old mode 100755
new mode 100644
index 5704d6a..9887b79
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
@@ -1,83 +1,83 @@
-using System;
-using System.Globalization;
-using Newtonsoft.Json.Utilities;
-
-namespace Newtonsoft.Json.Converters
-{
- ///
- /// Converts a to and from a JavaScript date constructor (e.g. new Date(52231943)).
- ///
- public class JavaScriptDateTimeConverter : JsonConverter
- {
- ///
- /// Writes the JSON representation of the object.
- ///
- /// The to write to.
- /// The value.
- public override void WriteJson(JsonWriter writer, object value)
- {
- long ticks;
-
- if (value is DateTime)
- {
- DateTime dateTime = (DateTime)value;
- DateTime utcDateTime = dateTime.ToUniversalTime();
- ticks = JavaScriptConvert.ConvertDateTimeToJavaScriptTicks(utcDateTime);
- }
- else
- {
- DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
- DateTimeOffset utcDateTimeOffset = dateTimeOffset.ToUniversalTime();
- ticks = JavaScriptConvert.ConvertDateTimeToJavaScriptTicks(utcDateTimeOffset.UtcDateTime);
- }
-
- writer.WriteStartConstructor("Date");
- writer.WriteValue(ticks);
- writer.WriteEndConstructor();
- }
-
- ///
- /// Reads the JSON representation of the object.
- ///
- /// The to read from.
- /// Type of the object.
- /// The object value.
- public override object ReadJson(JsonReader reader, Type objectType)
- {
- if (reader.TokenType != JsonToken.StartConstructor || string.Compare(reader.Value.ToString(), "Date", StringComparison.Ordinal) != 0)
- throw new Exception("Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
-
- reader.Read();
-
- if (reader.TokenType != JsonToken.Integer)
- throw new Exception("Unexpected token parsing date. Expected Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
-
- long ticks = (long)reader.Value;
-
- DateTime d = JavaScriptConvert.ConvertJavaScriptTicksToDateTime(ticks);
-
- reader.Read();
-
- if (reader.TokenType != JsonToken.EndConstructor)
- throw new Exception("Unexpected token parsing date. Expected EndConstructor, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
-
- if (objectType == typeof(DateTimeOffset))
- return new DateTimeOffset(d);
-
- return d;
- }
-
- ///
- /// Determines whether this instance can convert the specified object type.
- ///
- /// Type of the object.
- ///
- /// true if this instance can convert the specified object type; otherwise, false.
- ///
- public override bool CanConvert(Type objectType)
- {
- return (typeof(DateTime).IsAssignableFrom(objectType)
- || typeof(DateTimeOffset).IsAssignableFrom(objectType));
- }
- }
+using System;
+using System.Globalization;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a to and from a JavaScript date constructor (e.g. new Date(52231943)).
+ ///
+ public class JavaScriptDateTimeConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ public override void WriteJson(JsonWriter writer, object value)
+ {
+ long ticks;
+
+ if (value is DateTime)
+ {
+ DateTime dateTime = (DateTime)value;
+ DateTime utcDateTime = dateTime.ToUniversalTime();
+ ticks = JavaScriptConvert.ConvertDateTimeToJavaScriptTicks(utcDateTime);
+ }
+ else
+ {
+ DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
+ DateTimeOffset utcDateTimeOffset = dateTimeOffset.ToUniversalTime();
+ ticks = JavaScriptConvert.ConvertDateTimeToJavaScriptTicks(utcDateTimeOffset.UtcDateTime);
+ }
+
+ writer.WriteStartConstructor("Date");
+ writer.WriteValue(ticks);
+ writer.WriteEndConstructor();
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
+ public override object ReadJson(JsonReader reader, Type objectType)
+ {
+ if (reader.TokenType != JsonToken.StartConstructor || string.Compare(reader.Value.ToString(), "Date", StringComparison.Ordinal) != 0)
+ throw new Exception("Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
+
+ reader.Read();
+
+ if (reader.TokenType != JsonToken.Integer)
+ throw new Exception("Unexpected token parsing date. Expected Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+
+ long ticks = (long)reader.Value;
+
+ DateTime d = JavaScriptConvert.ConvertJavaScriptTicksToDateTime(ticks);
+
+ reader.Read();
+
+ if (reader.TokenType != JsonToken.EndConstructor)
+ throw new Exception("Unexpected token parsing date. Expected EndConstructor, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+
+ if (objectType == typeof(DateTimeOffset))
+ return new DateTimeOffset(d);
+
+ return d;
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+ return (typeof(DateTime).IsAssignableFrom(objectType)
+ || typeof(DateTimeOffset).IsAssignableFrom(objectType));
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
old mode 100755
new mode 100644
index ab53622..25c72f9
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
@@ -1,25 +1,25 @@
-namespace Newtonsoft.Json.Converters
-{
- ///
- /// Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC.
- ///
- public enum JsonDateTimeSerializationMode
- {
- ///
- /// The time represented is local time.
- ///
- Local,
- ///
- /// The time represented is UTC.
- ///
- Utc,
- ///
- /// The time represented is not specified as either local time or Coordinated Universal Time (UTC).
- ///
- Unspecified,
- ///
- /// Preserves the DateTimeKind field of a date when a DateTime object is converted to a string and the string is then converted back to a DateTime object.
- ///
- RoundtripKind
- }
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC.
+ ///
+ public enum JsonDateTimeSerializationMode
+ {
+ ///
+ /// The time represented is local time.
+ ///
+ Local,
+ ///
+ /// The time represented is UTC.
+ ///
+ Utc,
+ ///
+ /// The time represented is not specified as either local time or Coordinated Universal Time (UTC).
+ ///
+ Unspecified,
+ ///
+ /// Preserves the DateTimeKind field of a date when a DateTime object is converted to a string and the string is then converted back to a DateTime object.
+ ///
+ RoundtripKind
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/XmlNodeConverter.cs
old mode 100755
new mode 100644
index 79d8c56..2b52aea
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/XmlNodeConverter.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Converters/XmlNodeConverter.cs
@@ -1,552 +1,552 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Xml;
-using Newtonsoft.Json.Utilities;
-
-namespace Newtonsoft.Json.Converters
-{
- ///
- /// Converts an to and from JSON.
- ///
- public class XmlNodeConverter : JsonConverter
- {
- private const string TextName = "#text";
- private const string CommentName = "#comment";
- private const string CDataName = "#cdata-section";
- private const string WhitespaceName = "#whitespace";
- private const string SignificantWhitespaceName = "#significant-whitespace";
- private const string DeclarationName = "?xml";
- private const string JsonNamespaceUri = "http://james.newtonking.com/projects/json";
-
- #region Writing
- ///
- /// Writes the JSON representation of the object.
- ///
- /// The to write to.
- /// The value.
- public override void WriteJson(JsonWriter writer, object value)
- {
- XmlNode node = value as XmlNode;
-
- if (node == null)
- throw new ArgumentException("Value must be an XmlNode", "value");
-
- writer.WriteStartObject();
- SerializeNode(writer, node, true);
- writer.WriteEndObject();
- }
-
- private string GetPropertyName(XmlNode node)
- {
- switch (node.NodeType)
- {
- case XmlNodeType.Attribute:
- return "@" + node.Name;
- case XmlNodeType.CDATA:
- return CDataName;
- case XmlNodeType.Comment:
- return CommentName;
- case XmlNodeType.Element:
- return node.Name;
- case XmlNodeType.ProcessingInstruction:
- return "?" + node.Name;
- case XmlNodeType.XmlDeclaration:
- return DeclarationName;
- case XmlNodeType.SignificantWhitespace:
- return SignificantWhitespaceName;
- case XmlNodeType.Text:
- return TextName;
- case XmlNodeType.Whitespace:
- return WhitespaceName;
- default:
- throw new JsonSerializationException("Unexpected XmlNodeType when getting node name: " + node.NodeType);
- }
- }
-
- private void SerializeGroupedNodes(JsonWriter writer, XmlNode node)
- {
- // group nodes together by name
- Dictionary> nodesGroupedByName = new Dictionary>();
-
- for (int i = 0; i < node.ChildNodes.Count; i++)
- {
- XmlNode childNode = node.ChildNodes[i];
- string nodeName = GetPropertyName(childNode);
-
- List nodes;
- if (!nodesGroupedByName.TryGetValue(nodeName, out nodes))
- {
- nodes = new List();
- nodesGroupedByName.Add(nodeName, nodes);
- }
-
- nodes.Add(childNode);
- }
-
- // loop through grouped nodes. write single name instances as normal,
- // write multiple names together in an array
- foreach (KeyValuePair> nodeNameGroup in nodesGroupedByName)
- {
- List groupedNodes = nodeNameGroup.Value;
- bool writeArray;
-
- if (groupedNodes.Count == 1)
- {
- XmlNode singleNode = groupedNodes[0];
- XmlAttribute jsonArrayAttribute = (singleNode.Attributes != null) ? singleNode.Attributes["Array", JsonNamespaceUri] : null;
- if (jsonArrayAttribute != null)
- writeArray = XmlConvert.ToBoolean(jsonArrayAttribute.Value);
- else
- writeArray = false;
- }
- else
- {
- writeArray = true;
- }
-
- if (!writeArray)
- {
- SerializeNode(writer, groupedNodes[0], true);
- }
- else
- {
- string elementNames = nodeNameGroup.Key;
- writer.WritePropertyName(nodeNameGroup.Key);
- writer.WriteStartArray();
-
- for (int i = 0; i < groupedNodes.Count; i++)
- {
- SerializeNode(writer, groupedNodes[i], false);
- }
-
- writer.WriteEndArray();
- }
- }
- }
-
- private void SerializeNode(JsonWriter writer, XmlNode node, bool writePropertyName)
- {
- switch (node.NodeType)
- {
- case XmlNodeType.Document:
- case XmlNodeType.DocumentFragment:
- SerializeGroupedNodes(writer, node);
- break;
- case XmlNodeType.Element:
- if (writePropertyName)
- writer.WritePropertyName(node.Name);
-
- if (ValueAttributes(node.Attributes).Count() == 0 && node.ChildNodes.Count == 1
- && node.ChildNodes[0].NodeType == XmlNodeType.Text)
- {
- // write elements with a single text child as a name value pair
- writer.WriteValue(node.ChildNodes[0].Value);
- }
- else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
- {
- // empty element
- writer.WriteNull();
- }
- else if (node.ChildNodes.OfType().Where(x => x.Name.StartsWith("-")).Count() > 1)
- {
- XmlElement constructorValueElement = node.ChildNodes.OfType().Where(x => x.Name.StartsWith("-")).First();
- string constructorName = constructorValueElement.Name.Substring(1);
-
- writer.WriteStartConstructor(constructorName);
-
- for (int i = 0; i < node.ChildNodes.Count; i++)
- {
- SerializeNode(writer, node.ChildNodes[i], false);
- }
-
- writer.WriteEndConstructor();
- }
- else
- {
- writer.WriteStartObject();
-
- for (int i = 0; i < node.Attributes.Count; i++)
- {
- SerializeNode(writer, node.Attributes[i], true);
- }
-
- SerializeGroupedNodes(writer, node);
-
- writer.WriteEndObject();
- }
-
- break;
- case XmlNodeType.Comment:
- if (writePropertyName)
- writer.WriteComment(node.Value);
- break;
- case XmlNodeType.Attribute:
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- if (node.Prefix == "xmlns" && node.Value == JsonNamespaceUri)
- break;
- else if (node.NamespaceURI == JsonNamespaceUri)
- break;
-
- if (writePropertyName)
- writer.WritePropertyName(GetPropertyName(node));
- writer.WriteValue(node.Value);
- break;
- case XmlNodeType.XmlDeclaration:
- XmlDeclaration declaration = (XmlDeclaration)node;
- writer.WritePropertyName(GetPropertyName(node));
- writer.WriteStartObject();
-
- if (!string.IsNullOrEmpty(declaration.Version))
- {
- writer.WritePropertyName("@version");
- writer.WriteValue(declaration.Version);
- }
- if (!string.IsNullOrEmpty(declaration.Encoding))
- {
- writer.WritePropertyName("@encoding");
- writer.WriteValue(declaration.Encoding);
- }
- if (!string.IsNullOrEmpty(declaration.Standalone))
- {
- writer.WritePropertyName("@standalone");
- writer.WriteValue(declaration.Standalone);
- }
-
- writer.WriteEndObject();
- break;
- default:
- throw new JsonSerializationException("Unexpected XmlNodeType when serializing nodes: " + node.NodeType);
- }
- }
- #endregion
-
- #region Reading
- ///
- /// Reads the JSON representation of the object.
- ///
- /// The to read from.
- /// Type of the object.
- /// The object value.
- public override object ReadJson(JsonReader reader, Type objectType)
- {
- // maybe have CanReader and a CanWrite methods so this sort of test wouldn't be necessary
- if (objectType != typeof(XmlDocument))
- throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments");
-
- XmlDocument document = new XmlDocument();
- XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
-
- if (reader.TokenType != JsonToken.StartObject)
- throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object.");
-
- reader.Read();
-
- DeserializeNode(reader, document, manager, document);
-
- return document;
- }
-
- private void DeserializeValue(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, string propertyName, XmlNode currentNode)
- {
- switch (propertyName)
- {
- case TextName:
- currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
- break;
- case CDataName:
- currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
- break;
- case WhitespaceName:
- currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
- break;
- case SignificantWhitespaceName:
- currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
- break;
- default:
- // processing instructions and the xml declaration start with ?
- if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
- {
- if (propertyName == DeclarationName)
- {
- string version = null;
- string encoding = null;
- string standalone = null;
- while (reader.Read() && reader.TokenType != JsonToken.EndObject)
- {
- switch (reader.Value.ToString())
- {
- case "@version":
- reader.Read();
- version = reader.Value.ToString();
- break;
- case "@encoding":
- reader.Read();
- encoding = reader.Value.ToString();
- break;
- case "@standalone":
- reader.Read();
- standalone = reader.Value.ToString();
- break;
- default:
- throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
- }
- }
-
- XmlDeclaration declaration = document.CreateXmlDeclaration(version, encoding, standalone);
- currentNode.AppendChild(declaration);
- }
- else
- {
- XmlProcessingInstruction instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
- currentNode.AppendChild(instruction);
- }
- }
- else
- {
- // deserialize xml element
- bool finishedAttributes = false;
- bool finishedElement = false;
- string elementPrefix = GetPrefix(propertyName);
- Dictionary attributeNameValues = new Dictionary();
-
- // a string token means the element only has a single text child
- if (reader.TokenType != JsonToken.String
- && reader.TokenType != JsonToken.Null
- && reader.TokenType != JsonToken.Boolean
- && reader.TokenType != JsonToken.Integer
- && reader.TokenType != JsonToken.Float
- && reader.TokenType != JsonToken.Date
- && reader.TokenType != JsonToken.StartConstructor)
- {
- // read properties until first non-attribute is encountered
- while (!finishedAttributes && !finishedElement && reader.Read())
- {
- switch (reader.TokenType)
- {
- case JsonToken.PropertyName:
- string attributeName = reader.Value.ToString();
-
- if (attributeName[0] == '@')
- {
- attributeName = attributeName.Substring(1);
- reader.Read();
- string attributeValue = reader.Value.ToString();
- attributeNameValues.Add(attributeName, attributeValue);
-
- string namespacePrefix;
-
- if (IsNamespaceAttribute(attributeName, out namespacePrefix))
- {
- manager.AddNamespace(namespacePrefix, attributeValue);
- }
- }
- else
- {
- finishedAttributes = true;
- }
- break;
- case JsonToken.EndObject:
- finishedElement = true;
- break;
- default:
- throw new JsonSerializationException("Unexpected JsonToken: " + reader.TokenType);
- }
- }
- }
-
- // have to wait until attributes have been parsed before creating element
- // attributes may contain namespace info used by the element
- XmlElement element = (!string.IsNullOrEmpty(elementPrefix))
- ? document.CreateElement(propertyName, manager.LookupNamespace(elementPrefix))
- : document.CreateElement(propertyName);
-
- currentNode.AppendChild(element);
-
- // add attributes to newly created element
- foreach (KeyValuePair nameValue in attributeNameValues)
- {
- string attributePrefix = GetPrefix(nameValue.Key);
-
- XmlAttribute attribute = (!string.IsNullOrEmpty(attributePrefix))
- ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix))
- : document.CreateAttribute(nameValue.Key);
-
- attribute.Value = nameValue.Value;
-
- element.SetAttributeNode(attribute);
- }
-
- if (reader.TokenType == JsonToken.String)
- {
- element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
- }
- else if (reader.TokenType == JsonToken.Integer)
- {
- element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
- }
- else if (reader.TokenType == JsonToken.Float)
- {
- element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
- }
- else if (reader.TokenType == JsonToken.Boolean)
- {
- element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
- }
- else if (reader.TokenType == JsonToken.Date)
- {
- DateTime d = (DateTime)reader.Value;
- element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
- }
- else if (reader.TokenType == JsonToken.Null)
- {
- // empty element. do nothing
- }
- else
- {
- // finished element will have no children to deserialize
- if (!finishedElement)
- {
- manager.PushScope();
-
- DeserializeNode(reader, document, manager, element);
-
- manager.PopScope();
- }
- }
- }
- break;
- }
- }
-
- private void DeserializeNode(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, XmlNode currentNode)
- {
- do
- {
- switch (reader.TokenType)
- {
- case JsonToken.PropertyName:
- if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
- throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document.");
-
- string propertyName = reader.Value.ToString();
- reader.Read();
-
- if (reader.TokenType == JsonToken.StartArray)
- {
- while (reader.Read() && reader.TokenType != JsonToken.EndArray)
- {
- DeserializeValue(reader, document, manager, propertyName, currentNode);
- }
- }
- else
- {
- DeserializeValue(reader, document, manager, propertyName, currentNode);
- }
- break;
- case JsonToken.StartConstructor:
- string constructorName = reader.Value.ToString();
-
- while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
- {
- DeserializeValue(reader, document, manager, "-" + constructorName, currentNode);
- }
- break;
- case JsonToken.EndObject:
- case JsonToken.EndArray:
- return;
- default:
- throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
- }
- } while (reader.TokenType == JsonToken.PropertyName || reader.Read());
- // don't read if current token is a property. token was already read when parsing element attributes
- }
-
- ///
- /// Checks if the attributeName is a namespace attribute.
- ///
- /// Attribute name to test.
- /// The attribute name prefix if it has one, otherwise an empty string.
- /// True if attribute name is for a namespace attribute, otherwise false.
- private bool IsNamespaceAttribute(string attributeName, out string prefix)
- {
- if (attributeName.StartsWith("xmlns", StringComparison.Ordinal))
- {
- if (attributeName.Length == 5)
- {
- prefix = string.Empty;
- return true;
- }
- else if (attributeName[5] == ':')
- {
- prefix = attributeName.Substring(6, attributeName.Length - 6);
- return true;
- }
- }
- prefix = null;
- return false;
- }
-
- private string GetPrefix(string qualifiedName)
- {
- int colonPosition = qualifiedName.IndexOf(':');
-
- if ((colonPosition == -1 || colonPosition == 0) || (qualifiedName.Length - 1) == colonPosition)
- return string.Empty;
- else
- return qualifiedName.Substring(0, colonPosition);
- }
-
- private IEnumerable ValueAttributes(XmlAttributeCollection c)
- {
- return c.OfType().Where(a => a.NamespaceURI != JsonNamespaceUri);
- }
-
- private IEnumerable ValueNodes(XmlNodeList c)
- {
- return c.OfType().Where(n => n.NamespaceURI != JsonNamespaceUri);
- }
- #endregion
-
- ///
- /// Determines whether this instance can convert the specified value type.
- ///
- /// Type of the value.
- ///
- /// true if this instance can convert the specified value type; otherwise, false.
- ///
- public override bool CanConvert(Type valueType)
- {
- return typeof(XmlNode).IsAssignableFrom(valueType);
- }
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts an to and from JSON.
+ ///
+ public class XmlNodeConverter : JsonConverter
+ {
+ private const string TextName = "#text";
+ private const string CommentName = "#comment";
+ private const string CDataName = "#cdata-section";
+ private const string WhitespaceName = "#whitespace";
+ private const string SignificantWhitespaceName = "#significant-whitespace";
+ private const string DeclarationName = "?xml";
+ private const string JsonNamespaceUri = "http://james.newtonking.com/projects/json";
+
+ #region Writing
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ public override void WriteJson(JsonWriter writer, object value)
+ {
+ XmlNode node = value as XmlNode;
+
+ if (node == null)
+ throw new ArgumentException("Value must be an XmlNode", "value");
+
+ writer.WriteStartObject();
+ SerializeNode(writer, node, true);
+ writer.WriteEndObject();
+ }
+
+ private string GetPropertyName(XmlNode node)
+ {
+ switch (node.NodeType)
+ {
+ case XmlNodeType.Attribute:
+ return "@" + node.Name;
+ case XmlNodeType.CDATA:
+ return CDataName;
+ case XmlNodeType.Comment:
+ return CommentName;
+ case XmlNodeType.Element:
+ return node.Name;
+ case XmlNodeType.ProcessingInstruction:
+ return "?" + node.Name;
+ case XmlNodeType.XmlDeclaration:
+ return DeclarationName;
+ case XmlNodeType.SignificantWhitespace:
+ return SignificantWhitespaceName;
+ case XmlNodeType.Text:
+ return TextName;
+ case XmlNodeType.Whitespace:
+ return WhitespaceName;
+ default:
+ throw new JsonSerializationException("Unexpected XmlNodeType when getting node name: " + node.NodeType);
+ }
+ }
+
+ private void SerializeGroupedNodes(JsonWriter writer, XmlNode node)
+ {
+ // group nodes together by name
+ Dictionary> nodesGroupedByName = new Dictionary>();
+
+ for (int i = 0; i < node.ChildNodes.Count; i++)
+ {
+ XmlNode childNode = node.ChildNodes[i];
+ string nodeName = GetPropertyName(childNode);
+
+ List nodes;
+ if (!nodesGroupedByName.TryGetValue(nodeName, out nodes))
+ {
+ nodes = new List();
+ nodesGroupedByName.Add(nodeName, nodes);
+ }
+
+ nodes.Add(childNode);
+ }
+
+ // loop through grouped nodes. write single name instances as normal,
+ // write multiple names together in an array
+ foreach (KeyValuePair> nodeNameGroup in nodesGroupedByName)
+ {
+ List groupedNodes = nodeNameGroup.Value;
+ bool writeArray;
+
+ if (groupedNodes.Count == 1)
+ {
+ XmlNode singleNode = groupedNodes[0];
+ XmlAttribute jsonArrayAttribute = (singleNode.Attributes != null) ? singleNode.Attributes["Array", JsonNamespaceUri] : null;
+ if (jsonArrayAttribute != null)
+ writeArray = XmlConvert.ToBoolean(jsonArrayAttribute.Value);
+ else
+ writeArray = false;
+ }
+ else
+ {
+ writeArray = true;
+ }
+
+ if (!writeArray)
+ {
+ SerializeNode(writer, groupedNodes[0], true);
+ }
+ else
+ {
+ string elementNames = nodeNameGroup.Key;
+ writer.WritePropertyName(nodeNameGroup.Key);
+ writer.WriteStartArray();
+
+ for (int i = 0; i < groupedNodes.Count; i++)
+ {
+ SerializeNode(writer, groupedNodes[i], false);
+ }
+
+ writer.WriteEndArray();
+ }
+ }
+ }
+
+ private void SerializeNode(JsonWriter writer, XmlNode node, bool writePropertyName)
+ {
+ switch (node.NodeType)
+ {
+ case XmlNodeType.Document:
+ case XmlNodeType.DocumentFragment:
+ SerializeGroupedNodes(writer, node);
+ break;
+ case XmlNodeType.Element:
+ if (writePropertyName)
+ writer.WritePropertyName(node.Name);
+
+ if (ValueAttributes(node.Attributes).Count() == 0 && node.ChildNodes.Count == 1
+ && node.ChildNodes[0].NodeType == XmlNodeType.Text)
+ {
+ // write elements with a single text child as a name value pair
+ writer.WriteValue(node.ChildNodes[0].Value);
+ }
+ else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
+ {
+ // empty element
+ writer.WriteNull();
+ }
+ else if (node.ChildNodes.OfType().Where(x => x.Name.StartsWith("-")).Count() > 1)
+ {
+ XmlElement constructorValueElement = node.ChildNodes.OfType().Where(x => x.Name.StartsWith("-")).First();
+ string constructorName = constructorValueElement.Name.Substring(1);
+
+ writer.WriteStartConstructor(constructorName);
+
+ for (int i = 0; i < node.ChildNodes.Count; i++)
+ {
+ SerializeNode(writer, node.ChildNodes[i], false);
+ }
+
+ writer.WriteEndConstructor();
+ }
+ else
+ {
+ writer.WriteStartObject();
+
+ for (int i = 0; i < node.Attributes.Count; i++)
+ {
+ SerializeNode(writer, node.Attributes[i], true);
+ }
+
+ SerializeGroupedNodes(writer, node);
+
+ writer.WriteEndObject();
+ }
+
+ break;
+ case XmlNodeType.Comment:
+ if (writePropertyName)
+ writer.WriteComment(node.Value);
+ break;
+ case XmlNodeType.Attribute:
+ case XmlNodeType.Text:
+ case XmlNodeType.CDATA:
+ case XmlNodeType.ProcessingInstruction:
+ case XmlNodeType.Whitespace:
+ case XmlNodeType.SignificantWhitespace:
+ if (node.Prefix == "xmlns" && node.Value == JsonNamespaceUri)
+ break;
+ else if (node.NamespaceURI == JsonNamespaceUri)
+ break;
+
+ if (writePropertyName)
+ writer.WritePropertyName(GetPropertyName(node));
+ writer.WriteValue(node.Value);
+ break;
+ case XmlNodeType.XmlDeclaration:
+ XmlDeclaration declaration = (XmlDeclaration)node;
+ writer.WritePropertyName(GetPropertyName(node));
+ writer.WriteStartObject();
+
+ if (!string.IsNullOrEmpty(declaration.Version))
+ {
+ writer.WritePropertyName("@version");
+ writer.WriteValue(declaration.Version);
+ }
+ if (!string.IsNullOrEmpty(declaration.Encoding))
+ {
+ writer.WritePropertyName("@encoding");
+ writer.WriteValue(declaration.Encoding);
+ }
+ if (!string.IsNullOrEmpty(declaration.Standalone))
+ {
+ writer.WritePropertyName("@standalone");
+ writer.WriteValue(declaration.Standalone);
+ }
+
+ writer.WriteEndObject();
+ break;
+ default:
+ throw new JsonSerializationException("Unexpected XmlNodeType when serializing nodes: " + node.NodeType);
+ }
+ }
+ #endregion
+
+ #region Reading
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
+ public override object ReadJson(JsonReader reader, Type objectType)
+ {
+ // maybe have CanReader and a CanWrite methods so this sort of test wouldn't be necessary
+ if (objectType != typeof(XmlDocument))
+ throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments");
+
+ XmlDocument document = new XmlDocument();
+ XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
+
+ if (reader.TokenType != JsonToken.StartObject)
+ throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object.");
+
+ reader.Read();
+
+ DeserializeNode(reader, document, manager, document);
+
+ return document;
+ }
+
+ private void DeserializeValue(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, string propertyName, XmlNode currentNode)
+ {
+ switch (propertyName)
+ {
+ case TextName:
+ currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
+ break;
+ case CDataName:
+ currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
+ break;
+ case WhitespaceName:
+ currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
+ break;
+ case SignificantWhitespaceName:
+ currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
+ break;
+ default:
+ // processing instructions and the xml declaration start with ?
+ if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
+ {
+ if (propertyName == DeclarationName)
+ {
+ string version = null;
+ string encoding = null;
+ string standalone = null;
+ while (reader.Read() && reader.TokenType != JsonToken.EndObject)
+ {
+ switch (reader.Value.ToString())
+ {
+ case "@version":
+ reader.Read();
+ version = reader.Value.ToString();
+ break;
+ case "@encoding":
+ reader.Read();
+ encoding = reader.Value.ToString();
+ break;
+ case "@standalone":
+ reader.Read();
+ standalone = reader.Value.ToString();
+ break;
+ default:
+ throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
+ }
+ }
+
+ XmlDeclaration declaration = document.CreateXmlDeclaration(version, encoding, standalone);
+ currentNode.AppendChild(declaration);
+ }
+ else
+ {
+ XmlProcessingInstruction instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
+ currentNode.AppendChild(instruction);
+ }
+ }
+ else
+ {
+ // deserialize xml element
+ bool finishedAttributes = false;
+ bool finishedElement = false;
+ string elementPrefix = GetPrefix(propertyName);
+ Dictionary attributeNameValues = new Dictionary();
+
+ // a string token means the element only has a single text child
+ if (reader.TokenType != JsonToken.String
+ && reader.TokenType != JsonToken.Null
+ && reader.TokenType != JsonToken.Boolean
+ && reader.TokenType != JsonToken.Integer
+ && reader.TokenType != JsonToken.Float
+ && reader.TokenType != JsonToken.Date
+ && reader.TokenType != JsonToken.StartConstructor)
+ {
+ // read properties until first non-attribute is encountered
+ while (!finishedAttributes && !finishedElement && reader.Read())
+ {
+ switch (reader.TokenType)
+ {
+ case JsonToken.PropertyName:
+ string attributeName = reader.Value.ToString();
+
+ if (attributeName[0] == '@')
+ {
+ attributeName = attributeName.Substring(1);
+ reader.Read();
+ string attributeValue = reader.Value.ToString();
+ attributeNameValues.Add(attributeName, attributeValue);
+
+ string namespacePrefix;
+
+ if (IsNamespaceAttribute(attributeName, out namespacePrefix))
+ {
+ manager.AddNamespace(namespacePrefix, attributeValue);
+ }
+ }
+ else
+ {
+ finishedAttributes = true;
+ }
+ break;
+ case JsonToken.EndObject:
+ finishedElement = true;
+ break;
+ default:
+ throw new JsonSerializationException("Unexpected JsonToken: " + reader.TokenType);
+ }
+ }
+ }
+
+ // have to wait until attributes have been parsed before creating element
+ // attributes may contain namespace info used by the element
+ XmlElement element = (!string.IsNullOrEmpty(elementPrefix))
+ ? document.CreateElement(propertyName, manager.LookupNamespace(elementPrefix))
+ : document.CreateElement(propertyName);
+
+ currentNode.AppendChild(element);
+
+ // add attributes to newly created element
+ foreach (KeyValuePair nameValue in attributeNameValues)
+ {
+ string attributePrefix = GetPrefix(nameValue.Key);
+
+ XmlAttribute attribute = (!string.IsNullOrEmpty(attributePrefix))
+ ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix))
+ : document.CreateAttribute(nameValue.Key);
+
+ attribute.Value = nameValue.Value;
+
+ element.SetAttributeNode(attribute);
+ }
+
+ if (reader.TokenType == JsonToken.String)
+ {
+ element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
+ }
+ else if (reader.TokenType == JsonToken.Integer)
+ {
+ element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
+ }
+ else if (reader.TokenType == JsonToken.Float)
+ {
+ element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
+ }
+ else if (reader.TokenType == JsonToken.Boolean)
+ {
+ element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
+ }
+ else if (reader.TokenType == JsonToken.Date)
+ {
+ DateTime d = (DateTime)reader.Value;
+ element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
+ }
+ else if (reader.TokenType == JsonToken.Null)
+ {
+ // empty element. do nothing
+ }
+ else
+ {
+ // finished element will have no children to deserialize
+ if (!finishedElement)
+ {
+ manager.PushScope();
+
+ DeserializeNode(reader, document, manager, element);
+
+ manager.PopScope();
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ private void DeserializeNode(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, XmlNode currentNode)
+ {
+ do
+ {
+ switch (reader.TokenType)
+ {
+ case JsonToken.PropertyName:
+ if (currentNode.NodeType == XmlNodeType.Document && document.DocumentElement != null)
+ throw new JsonSerializationException("JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document.");
+
+ string propertyName = reader.Value.ToString();
+ reader.Read();
+
+ if (reader.TokenType == JsonToken.StartArray)
+ {
+ while (reader.Read() && reader.TokenType != JsonToken.EndArray)
+ {
+ DeserializeValue(reader, document, manager, propertyName, currentNode);
+ }
+ }
+ else
+ {
+ DeserializeValue(reader, document, manager, propertyName, currentNode);
+ }
+ break;
+ case JsonToken.StartConstructor:
+ string constructorName = reader.Value.ToString();
+
+ while (reader.Read() && reader.TokenType != JsonToken.EndConstructor)
+ {
+ DeserializeValue(reader, document, manager, "-" + constructorName, currentNode);
+ }
+ break;
+ case JsonToken.EndObject:
+ case JsonToken.EndArray:
+ return;
+ default:
+ throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
+ }
+ } while (reader.TokenType == JsonToken.PropertyName || reader.Read());
+ // don't read if current token is a property. token was already read when parsing element attributes
+ }
+
+ ///
+ /// Checks if the attributeName is a namespace attribute.
+ ///
+ /// Attribute name to test.
+ /// The attribute name prefix if it has one, otherwise an empty string.
+ /// True if attribute name is for a namespace attribute, otherwise false.
+ private bool IsNamespaceAttribute(string attributeName, out string prefix)
+ {
+ if (attributeName.StartsWith("xmlns", StringComparison.Ordinal))
+ {
+ if (attributeName.Length == 5)
+ {
+ prefix = string.Empty;
+ return true;
+ }
+ else if (attributeName[5] == ':')
+ {
+ prefix = attributeName.Substring(6, attributeName.Length - 6);
+ return true;
+ }
+ }
+ prefix = null;
+ return false;
+ }
+
+ private string GetPrefix(string qualifiedName)
+ {
+ int colonPosition = qualifiedName.IndexOf(':');
+
+ if ((colonPosition == -1 || colonPosition == 0) || (qualifiedName.Length - 1) == colonPosition)
+ return string.Empty;
+ else
+ return qualifiedName.Substring(0, colonPosition);
+ }
+
+ private IEnumerable ValueAttributes(XmlAttributeCollection c)
+ {
+ return c.OfType().Where(a => a.NamespaceURI != JsonNamespaceUri);
+ }
+
+ private IEnumerable ValueNodes(XmlNodeList c)
+ {
+ return c.OfType().Where(n => n.NamespaceURI != JsonNamespaceUri);
+ }
+ #endregion
+
+ ///
+ /// Determines whether this instance can convert the specified value type.
+ ///
+ /// Type of the value.
+ ///
+ /// true if this instance can convert the specified value type; otherwise, false.
+ ///
+ public override bool CanConvert(Type valueType)
+ {
+ return typeof(XmlNode).IsAssignableFrom(valueType);
+ }
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Identifier.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Identifier.cs
old mode 100755
new mode 100644
index df4e28c..bccbe43
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Identifier.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/Identifier.cs
@@ -1,156 +1,156 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Web;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Web.UI.WebControls;
-using System.ComponentModel;
-
-namespace Newtonsoft.Json
-{
- ///
- ///
- ///
- public class Identifier
- {
- private string _name;
-
- ///
- /// Gets the name.
- ///
- /// The name.
- public string Name
- {
- get { return _name; }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The name.
- public Identifier(string name)
- {
- _name = name;
- }
-
- private static bool IsAsciiLetter(char c)
- {
- return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
- }
-
- ///
- /// Determines whether the specified is equal to the current .
- ///
- /// The to compare with the current .
- ///
- /// true if the specified is equal to the current ; otherwise, false.
- ///
- /// The parameter is null.
- public override bool Equals(object obj)
- {
- Identifier function = obj as Identifier;
-
- return Equals(function);
- }
-
- ///
- /// Equalses the specified function.
- ///
- /// The function.
- ///
- public bool Equals(Identifier function)
- {
- return (_name == function.Name);
- }
-
- ///
- /// Equalses the specified a.
- ///
- /// A.
- /// The b.
- ///
- public static bool Equals(Identifier a, Identifier b)
- {
- if (a == b)
- return true;
-
- if (a != null && b != null)
- return a.Equals(b);
-
- return false;
- }
-
- ///
- /// Serves as a hash function for a particular type.
- ///
- ///
- /// A hash code for the current .
- ///
- public override int GetHashCode()
- {
- return _name.GetHashCode();
- }
-
- ///
- /// Returns a that represents the current .
- ///
- ///
- /// A that represents the current .
- ///
- public override string ToString()
- {
- return _name;
- }
-
- ///
- /// Implements the operator ==.
- ///
- /// A.
- /// The b.
- /// The result of the operator.
- public static bool operator ==(Identifier a, Identifier b)
- {
- return Identifier.Equals(a, b);
- }
-
- ///
- /// Implements the operator !=.
- ///
- /// A.
- /// The b.
- /// The result of the operator.
- public static bool operator !=(Identifier a, Identifier b)
- {
- return !Identifier.Equals(a, b);
- }
- }
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Web;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Web.UI.WebControls;
+using System.ComponentModel;
+
+namespace Newtonsoft.Json
+{
+ ///
+ ///
+ ///
+ public class Identifier
+ {
+ private string _name;
+
+ ///
+ /// Gets the name.
+ ///
+ /// The name.
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The name.
+ public Identifier(string name)
+ {
+ _name = name;
+ }
+
+ private static bool IsAsciiLetter(char c)
+ {
+ return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
+ }
+
+ ///
+ /// Determines whether the specified is equal to the current .
+ ///
+ /// The to compare with the current .
+ ///
+ /// true if the specified is equal to the current ; otherwise, false.
+ ///
+ /// The parameter is null.
+ public override bool Equals(object obj)
+ {
+ Identifier function = obj as Identifier;
+
+ return Equals(function);
+ }
+
+ ///
+ /// Equalses the specified function.
+ ///
+ /// The function.
+ ///
+ public bool Equals(Identifier function)
+ {
+ return (_name == function.Name);
+ }
+
+ ///
+ /// Equalses the specified a.
+ ///
+ /// A.
+ /// The b.
+ ///
+ public static bool Equals(Identifier a, Identifier b)
+ {
+ if (a == b)
+ return true;
+
+ if (a != null && b != null)
+ return a.Equals(b);
+
+ return false;
+ }
+
+ ///
+ /// Serves as a hash function for a particular type.
+ ///
+ ///
+ /// A hash code for the current .
+ ///
+ public override int GetHashCode()
+ {
+ return _name.GetHashCode();
+ }
+
+ ///
+ /// Returns a that represents the current .
+ ///
+ ///
+ /// A that represents the current .
+ ///
+ public override string ToString()
+ {
+ return _name;
+ }
+
+ ///
+ /// Implements the operator ==.
+ ///
+ /// A.
+ /// The b.
+ /// The result of the operator.
+ public static bool operator ==(Identifier a, Identifier b)
+ {
+ return Identifier.Equals(a, b);
+ }
+
+ ///
+ /// Implements the operator !=.
+ ///
+ /// A.
+ /// The b.
+ /// The result of the operator.
+ public static bool operator !=(Identifier a, Identifier b)
+ {
+ return !Identifier.Equals(a, b);
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JavaScriptConvert.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JavaScriptConvert.cs
old mode 100755
new mode 100644
index 8422469..a20c4dc
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JavaScriptConvert.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JavaScriptConvert.cs
@@ -1,542 +1,542 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Drawing;
-using System.Web.UI.WebControls;
-using System.Collections;
-using System.IO;
-using System.Globalization;
-using System.Runtime.Serialization;
-using System.Reflection;
-using System.Data.SqlTypes;
-using Newtonsoft.Json.Utilities;
-using System.Xml;
-using Newtonsoft.Json.Converters;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Provides methods for converting between common language runtime types and JavaScript types.
- ///
- public static class JavaScriptConvert
- {
- ///
- /// Represents JavaScript's boolean value true as a string. This field is read-only.
- ///
- public static readonly string True;
-
- ///
- /// Represents JavaScript's boolean value false as a string. This field is read-only.
- ///
- public static readonly string False;
-
- ///
- /// Represents JavaScript's null as a string. This field is read-only.
- ///
- public static readonly string Null;
-
- ///
- /// Represents JavaScript's undefined as a string. This field is read-only.
- ///
- public static readonly string Undefined;
-
- ///
- /// Represents JavaScript's positive infinity as a string. This field is read-only.
- ///
- public static readonly string PositiveInfinity;
-
- ///
- /// Represents JavaScript's negative infinity as a string. This field is read-only.
- ///
- public static readonly string NegativeInfinity;
-
- ///
- /// Represents JavaScript's NaN as a string. This field is read-only.
- ///
- public static readonly string NaN;
-
- internal static long InitialJavaScriptDateTicks;
- internal static DateTime MinimumJavaScriptDate;
-
- static JavaScriptConvert()
- {
- True = "true";
- False = "false";
- Null = "null";
- Undefined = "undefined";
- PositiveInfinity = "Infinity";
- NegativeInfinity = "-Infinity";
- NaN = "NaN";
-
- InitialJavaScriptDateTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;
- MinimumJavaScriptDate = new DateTime(100, 1, 1);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(DateTime value)
- {
- return ToStringInternal(new DateTimeOffset(value), value.Kind);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(DateTimeOffset value)
- {
- return ToStringInternal(value, DateTimeKind.Local);
- }
-
- internal static string ToStringInternal(DateTimeOffset value, DateTimeKind kind)
- {
- long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value);
-
- string offset;
- switch (kind)
- {
- case DateTimeKind.Local:
- case DateTimeKind.Unspecified:
- TimeSpan utcOffset = value.Offset;
- offset = utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
- break;
- default:
- offset = string.Empty;
- break;
- }
- return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + offset + @")\/""";
- }
-
- internal static long ConvertDateTimeToJavaScriptTicks(DateTimeOffset dateTime)
- {
- DateTimeOffset utcDateTime = dateTime.ToUniversalTime();
-
- //if (utcDateTime < MinimumJavaScriptDate)
- // utcDateTime = MinimumJavaScriptDate;
-
- long javaScriptTicks = (utcDateTime.Ticks - InitialJavaScriptDateTicks) / (long)10000;
-
- return javaScriptTicks;
- }
-
- internal static DateTime ConvertJavaScriptTicksToDateTime(long javaScriptTicks)
- {
- DateTime dateTime = new DateTime((javaScriptTicks * 10000) + InitialJavaScriptDateTicks, DateTimeKind.Utc);
-
- return dateTime;
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(bool value)
- {
- return (value) ? True : False;
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(char value)
- {
- return ToString(char.ToString(value));
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(Enum value)
- {
- return Enum.Format(value.GetType(), value, "D");
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(int value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(short value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(ushort value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(uint value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(long value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(ulong value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(float value)
- {
- return value.ToString("R", CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(double value)
- {
- return value.ToString("R", CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(byte value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(sbyte value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(decimal value)
- {
- return value.ToString(null, CultureInfo.InvariantCulture);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(Guid value)
- {
- return '"' + value.ToString("D", CultureInfo.InvariantCulture) + '"';
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(string value)
- {
- return ToString(value, '"');
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// The string delimiter character.
- /// A Json string representation of the .
- public static string ToString(string value, char delimter)
- {
- return JavaScriptUtils.ToEscapedJavaScriptString(value, delimter, true);
- }
-
- ///
- /// Converts the to it's JavaScript string representation.
- ///
- /// The value to convert.
- /// A Json string representation of the .
- public static string ToString(object value)
- {
- if (value == null)
- {
- return Null;
- }
- else if (value is IConvertible)
- {
- IConvertible convertible = value as IConvertible;
-
- switch (convertible.GetTypeCode())
- {
- case TypeCode.String:
- return ToString((string)convertible);
- case TypeCode.Char:
- return ToString((char)convertible);
- case TypeCode.Boolean:
- return ToString((bool)convertible);
- case TypeCode.SByte:
- return ToString((sbyte)convertible);
- case TypeCode.Int16:
- return ToString((short)convertible);
- case TypeCode.UInt16:
- return ToString((ushort)convertible);
- case TypeCode.Int32:
- return ToString((int)convertible);
- case TypeCode.Byte:
- return ToString((byte)convertible);
- case TypeCode.UInt32:
- return ToString((uint)convertible);
- case TypeCode.Int64:
- return ToString((long)convertible);
- case TypeCode.UInt64:
- return ToString((ulong)convertible);
- case TypeCode.Single:
- return ToString((float)convertible);
- case TypeCode.Double:
- return ToString((double)convertible);
- case TypeCode.DateTime:
- return ToString((DateTime)convertible);
- case TypeCode.Decimal:
- return ToString((decimal)convertible);
- }
- }
- else if (value is DateTimeOffset)
- {
- return ToString((DateTimeOffset)value);
- }
- else if (value is Guid)
- {
- return ToString((Guid)value);
- }
-
- throw new ArgumentException("Unsupported type: {0}. Use the JsonSerializer class to get the object's JSON representation.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
- }
-
- ///
- /// Serializes the specified object to a JSON string.
- ///
- /// The object to serialize.
- /// A JSON string representation of the object.
- public static string SerializeObject(object value)
- {
- return SerializeObject(value, null);
- }
-
- ///
- /// Serializes the specified object to a JSON string using a collection of .
- ///
- /// The object to serialize.
- /// A collection converters used while serializing.
- /// A JSON string representation of the object.
- public static string SerializeObject(object value, params JsonConverter[] converters)
- {
- StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
- JsonSerializer jsonSerializer = new JsonSerializer();
-
- if (!CollectionUtils.IsNullOrEmpty(converters))
- {
- for (int i = 0; i < converters.Length; i++)
- {
- jsonSerializer.Converters.Add(converters[i]);
- }
- }
-
- using (JsonWriter jsonWriter = new JsonTextWriter(sw))
- {
- //jsonWriter.Formatting = Formatting.Indented;
- jsonSerializer.Serialize(jsonWriter, value);
- }
-
- return sw.ToString();
- }
-
- ///
- /// Deserializes the specified object to a Json object.
- ///
- /// The object to deserialize.
- /// The deserialized object from the Json string.
- public static object DeserializeObject(string value)
- {
- return DeserializeObject(value, null, null);
- }
-
- ///
- /// Deserializes the specified object to a Json object.
- ///
- /// The object to deserialize.
- /// The of object being deserialized.
- /// The deserialized object from the Json string.
- public static object DeserializeObject(string value, Type type)
- {
- return DeserializeObject(value, type, null);
- }
-
- ///
- /// Deserializes the specified object to a Json object.
- ///
- /// The type of the object to deserialize.
- /// The object to deserialize.
- /// The deserialized object from the Json string.
- public static T DeserializeObject(string value)
- {
- return DeserializeObject(value, null);
- }
-
- ///
- /// Deserializes the specified JSON to the given anonymous type.
- ///
- ///
- /// The anonymous type to deserialize to. This can't be specified
- /// traditionally and must be infered from the anonymous type passed
- /// as a parameter.
- ///
- /// The object to deserialize.
- /// The anonymous type object.
- /// The deserialized anonymous type from the JSON string.
- public static T DeserializeAnonymousType(string value, T anonymousTypeObject)
- {
- return DeserializeObject(value);
- }
-
- ///
- /// Deserializes the JSON string to the specified type.
- ///
- /// The type of the object to deserialize.
- /// The object to deserialize.
- /// Converters to use while deserializing.
- /// The deserialized object from the JSON string.
- public static T DeserializeObject(string value, params JsonConverter[] converters)
- {
- return (T)DeserializeObject(value, typeof(T), converters);
- }
-
- ///
- /// Deserializes the JSON string to the specified type.
- ///
- /// The object to deserialize.
- /// The type of the object to deserialize.
- /// Converters to use while deserializing.
- /// The deserialized object from the JSON string.
- public static object DeserializeObject(string value, Type type, params JsonConverter[] converters)
- {
- StringReader sr = new StringReader(value);
- JsonSerializer jsonSerializer = new JsonSerializer();
-
- if (!CollectionUtils.IsNullOrEmpty(converters))
- {
- for (int i = 0; i < converters.Length; i++)
- {
- jsonSerializer.Converters.Add(converters[i]);
- }
- }
-
- object deserializedValue;
-
- using (JsonReader jsonReader = new JsonTextReader(sr))
- {
- deserializedValue = jsonSerializer.Deserialize(jsonReader, type);
- }
-
- return deserializedValue;
- }
-
- ///
- /// Serializes the XML node to a JSON string.
- ///
- /// The node to serialize.
- /// A JSON string of the XmlNode.
- public static string SerializeXmlNode(XmlNode node)
- {
- XmlNodeConverter converter = new XmlNodeConverter();
-
- return SerializeObject(node, converter);
- }
-
- ///
- /// Deserializes the XmlNode from a JSON string.
- ///
- /// The JSON string.
- /// The deserialized XmlNode
- public static XmlNode DeserializeXmlNode(string value)
- {
- XmlNodeConverter converter = new XmlNodeConverter();
-
- return (XmlDocument)DeserializeObject(value, typeof(XmlDocument), converter);
- }
- }
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+using System.Web.UI.WebControls;
+using System.Collections;
+using System.IO;
+using System.Globalization;
+using System.Runtime.Serialization;
+using System.Reflection;
+using System.Data.SqlTypes;
+using Newtonsoft.Json.Utilities;
+using System.Xml;
+using Newtonsoft.Json.Converters;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Provides methods for converting between common language runtime types and JavaScript types.
+ ///
+ public static class JavaScriptConvert
+ {
+ ///
+ /// Represents JavaScript's boolean value true as a string. This field is read-only.
+ ///
+ public static readonly string True;
+
+ ///
+ /// Represents JavaScript's boolean value false as a string. This field is read-only.
+ ///
+ public static readonly string False;
+
+ ///
+ /// Represents JavaScript's null as a string. This field is read-only.
+ ///
+ public static readonly string Null;
+
+ ///
+ /// Represents JavaScript's undefined as a string. This field is read-only.
+ ///
+ public static readonly string Undefined;
+
+ ///
+ /// Represents JavaScript's positive infinity as a string. This field is read-only.
+ ///
+ public static readonly string PositiveInfinity;
+
+ ///
+ /// Represents JavaScript's negative infinity as a string. This field is read-only.
+ ///
+ public static readonly string NegativeInfinity;
+
+ ///
+ /// Represents JavaScript's NaN as a string. This field is read-only.
+ ///
+ public static readonly string NaN;
+
+ internal static long InitialJavaScriptDateTicks;
+ internal static DateTime MinimumJavaScriptDate;
+
+ static JavaScriptConvert()
+ {
+ True = "true";
+ False = "false";
+ Null = "null";
+ Undefined = "undefined";
+ PositiveInfinity = "Infinity";
+ NegativeInfinity = "-Infinity";
+ NaN = "NaN";
+
+ InitialJavaScriptDateTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;
+ MinimumJavaScriptDate = new DateTime(100, 1, 1);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(DateTime value)
+ {
+ return ToStringInternal(new DateTimeOffset(value), value.Kind);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(DateTimeOffset value)
+ {
+ return ToStringInternal(value, DateTimeKind.Local);
+ }
+
+ internal static string ToStringInternal(DateTimeOffset value, DateTimeKind kind)
+ {
+ long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value);
+
+ string offset;
+ switch (kind)
+ {
+ case DateTimeKind.Local:
+ case DateTimeKind.Unspecified:
+ TimeSpan utcOffset = value.Offset;
+ offset = utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
+ break;
+ default:
+ offset = string.Empty;
+ break;
+ }
+ return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + offset + @")\/""";
+ }
+
+ internal static long ConvertDateTimeToJavaScriptTicks(DateTimeOffset dateTime)
+ {
+ DateTimeOffset utcDateTime = dateTime.ToUniversalTime();
+
+ //if (utcDateTime < MinimumJavaScriptDate)
+ // utcDateTime = MinimumJavaScriptDate;
+
+ long javaScriptTicks = (utcDateTime.Ticks - InitialJavaScriptDateTicks) / (long)10000;
+
+ return javaScriptTicks;
+ }
+
+ internal static DateTime ConvertJavaScriptTicksToDateTime(long javaScriptTicks)
+ {
+ DateTime dateTime = new DateTime((javaScriptTicks * 10000) + InitialJavaScriptDateTicks, DateTimeKind.Utc);
+
+ return dateTime;
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(bool value)
+ {
+ return (value) ? True : False;
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(char value)
+ {
+ return ToString(char.ToString(value));
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(Enum value)
+ {
+ return Enum.Format(value.GetType(), value, "D");
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(int value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(short value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(ushort value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(uint value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(long value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(ulong value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(float value)
+ {
+ return value.ToString("R", CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(double value)
+ {
+ return value.ToString("R", CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(byte value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(sbyte value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(decimal value)
+ {
+ return value.ToString(null, CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(Guid value)
+ {
+ return '"' + value.ToString("D", CultureInfo.InvariantCulture) + '"';
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(string value)
+ {
+ return ToString(value, '"');
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// The string delimiter character.
+ /// A Json string representation of the .
+ public static string ToString(string value, char delimter)
+ {
+ return JavaScriptUtils.ToEscapedJavaScriptString(value, delimter, true);
+ }
+
+ ///
+ /// Converts the to it's JavaScript string representation.
+ ///
+ /// The value to convert.
+ /// A Json string representation of the .
+ public static string ToString(object value)
+ {
+ if (value == null)
+ {
+ return Null;
+ }
+ else if (value is IConvertible)
+ {
+ IConvertible convertible = value as IConvertible;
+
+ switch (convertible.GetTypeCode())
+ {
+ case TypeCode.String:
+ return ToString((string)convertible);
+ case TypeCode.Char:
+ return ToString((char)convertible);
+ case TypeCode.Boolean:
+ return ToString((bool)convertible);
+ case TypeCode.SByte:
+ return ToString((sbyte)convertible);
+ case TypeCode.Int16:
+ return ToString((short)convertible);
+ case TypeCode.UInt16:
+ return ToString((ushort)convertible);
+ case TypeCode.Int32:
+ return ToString((int)convertible);
+ case TypeCode.Byte:
+ return ToString((byte)convertible);
+ case TypeCode.UInt32:
+ return ToString((uint)convertible);
+ case TypeCode.Int64:
+ return ToString((long)convertible);
+ case TypeCode.UInt64:
+ return ToString((ulong)convertible);
+ case TypeCode.Single:
+ return ToString((float)convertible);
+ case TypeCode.Double:
+ return ToString((double)convertible);
+ case TypeCode.DateTime:
+ return ToString((DateTime)convertible);
+ case TypeCode.Decimal:
+ return ToString((decimal)convertible);
+ }
+ }
+ else if (value is DateTimeOffset)
+ {
+ return ToString((DateTimeOffset)value);
+ }
+ else if (value is Guid)
+ {
+ return ToString((Guid)value);
+ }
+
+ throw new ArgumentException("Unsupported type: {0}. Use the JsonSerializer class to get the object's JSON representation.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
+ }
+
+ ///
+ /// Serializes the specified object to a JSON string.
+ ///
+ /// The object to serialize.
+ /// A JSON string representation of the object.
+ public static string SerializeObject(object value)
+ {
+ return SerializeObject(value, null);
+ }
+
+ ///
+ /// Serializes the specified object to a JSON string using a collection of .
+ ///
+ /// The object to serialize.
+ /// A collection converters used while serializing.
+ /// A JSON string representation of the object.
+ public static string SerializeObject(object value, params JsonConverter[] converters)
+ {
+ StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
+ JsonSerializer jsonSerializer = new JsonSerializer();
+
+ if (!CollectionUtils.IsNullOrEmpty(converters))
+ {
+ for (int i = 0; i < converters.Length; i++)
+ {
+ jsonSerializer.Converters.Add(converters[i]);
+ }
+ }
+
+ using (JsonWriter jsonWriter = new JsonTextWriter(sw))
+ {
+ //jsonWriter.Formatting = Formatting.Indented;
+ jsonSerializer.Serialize(jsonWriter, value);
+ }
+
+ return sw.ToString();
+ }
+
+ ///
+ /// Deserializes the specified object to a Json object.
+ ///
+ /// The object to deserialize.
+ /// The deserialized object from the Json string.
+ public static object DeserializeObject(string value)
+ {
+ return DeserializeObject(value, null, null);
+ }
+
+ ///
+ /// Deserializes the specified object to a Json object.
+ ///
+ /// The object to deserialize.
+ /// The of object being deserialized.
+ /// The deserialized object from the Json string.
+ public static object DeserializeObject(string value, Type type)
+ {
+ return DeserializeObject(value, type, null);
+ }
+
+ ///
+ /// Deserializes the specified object to a Json object.
+ ///
+ /// The type of the object to deserialize.
+ /// The object to deserialize.
+ /// The deserialized object from the Json string.
+ public static T DeserializeObject(string value)
+ {
+ return DeserializeObject(value, null);
+ }
+
+ ///
+ /// Deserializes the specified JSON to the given anonymous type.
+ ///
+ ///
+ /// The anonymous type to deserialize to. This can't be specified
+ /// traditionally and must be infered from the anonymous type passed
+ /// as a parameter.
+ ///
+ /// The object to deserialize.
+ /// The anonymous type object.
+ /// The deserialized anonymous type from the JSON string.
+ public static T DeserializeAnonymousType(string value, T anonymousTypeObject)
+ {
+ return DeserializeObject(value);
+ }
+
+ ///
+ /// Deserializes the JSON string to the specified type.
+ ///
+ /// The type of the object to deserialize.
+ /// The object to deserialize.
+ /// Converters to use while deserializing.
+ /// The deserialized object from the JSON string.
+ public static T DeserializeObject(string value, params JsonConverter[] converters)
+ {
+ return (T)DeserializeObject(value, typeof(T), converters);
+ }
+
+ ///
+ /// Deserializes the JSON string to the specified type.
+ ///
+ /// The object to deserialize.
+ /// The type of the object to deserialize.
+ /// Converters to use while deserializing.
+ /// The deserialized object from the JSON string.
+ public static object DeserializeObject(string value, Type type, params JsonConverter[] converters)
+ {
+ StringReader sr = new StringReader(value);
+ JsonSerializer jsonSerializer = new JsonSerializer();
+
+ if (!CollectionUtils.IsNullOrEmpty(converters))
+ {
+ for (int i = 0; i < converters.Length; i++)
+ {
+ jsonSerializer.Converters.Add(converters[i]);
+ }
+ }
+
+ object deserializedValue;
+
+ using (JsonReader jsonReader = new JsonTextReader(sr))
+ {
+ deserializedValue = jsonSerializer.Deserialize(jsonReader, type);
+ }
+
+ return deserializedValue;
+ }
+
+ ///
+ /// Serializes the XML node to a JSON string.
+ ///
+ /// The node to serialize.
+ /// A JSON string of the XmlNode.
+ public static string SerializeXmlNode(XmlNode node)
+ {
+ XmlNodeConverter converter = new XmlNodeConverter();
+
+ return SerializeObject(node, converter);
+ }
+
+ ///
+ /// Deserializes the XmlNode from a JSON string.
+ ///
+ /// The JSON string.
+ /// The deserialized XmlNode
+ public static XmlNode DeserializeXmlNode(string value)
+ {
+ XmlNodeConverter converter = new XmlNodeConverter();
+
+ return (XmlDocument)DeserializeObject(value, typeof(XmlDocument), converter);
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverter.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverter.cs
old mode 100755
new mode 100644
index 386c1b5..1bc9f11
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverter.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverter.cs
@@ -1,62 +1,62 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json.Utilities;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Converts an object to and from JSON.
- ///
- public abstract class JsonConverter
- {
- ///
- /// Writes the JSON representation of the object.
- ///
- /// The to write to.
- /// The value.
- public abstract void WriteJson(JsonWriter writer, object value);
-
- ///
- /// Reads the JSON representation of the object.
- ///
- /// The to read from.
- /// Type of the object.
- /// The object value.
- public abstract object ReadJson(JsonReader reader, Type objectType);
-
- ///
- /// Determines whether this instance can convert the specified object type.
- ///
- /// Type of the object.
- ///
- /// true if this instance can convert the specified object type; otherwise, false.
- ///
- public abstract bool CanConvert(Type objectType);
- }
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Converts an object to and from JSON.
+ ///
+ public abstract class JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ public abstract void WriteJson(JsonWriter writer, object value);
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
+ public abstract object ReadJson(JsonReader reader, Type objectType);
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public abstract bool CanConvert(Type objectType);
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverterCollection.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverterCollection.cs
old mode 100755
new mode 100644
index 50f70c5..a2a2bea
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverterCollection.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonConverterCollection.cs
@@ -1,39 +1,39 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Collections.ObjectModel;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Represents a collection of .
- ///
- public class JsonConverterCollection : Collection
- {
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Collections.ObjectModel;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Represents a collection of .
+ ///
+ public class JsonConverterCollection : Collection
+ {
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonHandler.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonHandler.cs
old mode 100755
new mode 100644
index 1f81131..ca2a93f
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonHandler.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonHandler.cs
@@ -1,63 +1,63 @@
-using System;
-using System.Web;
-using System.Web.Caching;
-using System.Xml;
-using System.Text;
-using System.Security.Principal;
-
-namespace Newtonsoft.Json
-{
- public abstract class JsonHandler : HandlerBase, IHttpHandler
- {
- public event EventHandler Error;
-
- protected abstract void WriteResult(JsonWriter writer);
-
- public static void JsonResponse(HttpResponse response, Action writeAction)
- {
- response.ClearHeaders();
- response.ClearContent();
-
- JsonWriter writer = new JsonWriter(response.Output);
-
- writeAction(writer);
-
- writer.Flush();
- }
-
- protected virtual void OnError(EventArgs e)
- {
- if (Error != null)
- {
- Error(this, e);
- }
- }
-
- void IHttpHandler.ProcessRequest(HttpContext context)
- {
- if (context == null)
- throw new ArgumentNullException("context");
-
- Context = context;
-
- try
- {
- JsonHandler.JsonResponse(context.Response, new Action(WriteResult));
- }
- catch (Exception exception)
- {
- context.AddError(exception);
- OnError(EventArgs.Empty);
- if (context.Error != null)
- {
- throw new HttpUnhandledException("blah", exception);
- }
- }
- }
-
- bool IHttpHandler.IsReusable
- {
- get { return false; }
- }
- }
+using System;
+using System.Web;
+using System.Web.Caching;
+using System.Xml;
+using System.Text;
+using System.Security.Principal;
+
+namespace Newtonsoft.Json
+{
+ public abstract class JsonHandler : HandlerBase, IHttpHandler
+ {
+ public event EventHandler Error;
+
+ protected abstract void WriteResult(JsonWriter writer);
+
+ public static void JsonResponse(HttpResponse response, Action writeAction)
+ {
+ response.ClearHeaders();
+ response.ClearContent();
+
+ JsonWriter writer = new JsonWriter(response.Output);
+
+ writeAction(writer);
+
+ writer.Flush();
+ }
+
+ protected virtual void OnError(EventArgs e)
+ {
+ if (Error != null)
+ {
+ Error(this, e);
+ }
+ }
+
+ void IHttpHandler.ProcessRequest(HttpContext context)
+ {
+ if (context == null)
+ throw new ArgumentNullException("context");
+
+ Context = context;
+
+ try
+ {
+ JsonHandler.JsonResponse(context.Response, new Action(WriteResult));
+ }
+ catch (Exception exception)
+ {
+ context.AddError(exception);
+ OnError(EventArgs.Empty);
+ if (context.Error != null)
+ {
+ throw new HttpUnhandledException("blah", exception);
+ }
+ }
+ }
+
+ bool IHttpHandler.IsReusable
+ {
+ get { return false; }
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonIgnoreAttribute.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonIgnoreAttribute.cs
old mode 100755
new mode 100644
index e7511a0..f736c8c
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonIgnoreAttribute.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonIgnoreAttribute.cs
@@ -1,39 +1,39 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Instructs the not to serialize the public field or public read/write property value.
- ///
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
- public sealed class JsonIgnoreAttribute : Attribute
- {
- }
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Instructs the not to serialize the public field or public read/write property value.
+ ///
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
+ public sealed class JsonIgnoreAttribute : Attribute
+ {
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonObjectAttribute.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonObjectAttribute.cs
old mode 100755
new mode 100644
index 317e834..659f67a
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonObjectAttribute.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonObjectAttribute.cs
@@ -1,64 +1,64 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Instructs the how to serialize the object.
- ///
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
- public sealed class JsonObjectAttribute : Attribute
- {
- private MemberSerialization _memberSerialization = MemberSerialization.OptOut;
-
- ///
- /// Gets or sets the member serialization.
- ///
- /// The member serialization.
- public MemberSerialization MemberSerialization
- {
- get { return _memberSerialization; }
- set { _memberSerialization = value; }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public JsonObjectAttribute()
- {
- }
-
- ///
- /// Initializes a new instance of the class with the specified member serialization.
- ///
- /// The member serialization.
- public JsonObjectAttribute(MemberSerialization memberSerialization)
- {
- MemberSerialization = memberSerialization;
- }
- }
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Instructs the how to serialize the object.
+ ///
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
+ public sealed class JsonObjectAttribute : Attribute
+ {
+ private MemberSerialization _memberSerialization = MemberSerialization.OptOut;
+
+ ///
+ /// Gets or sets the member serialization.
+ ///
+ /// The member serialization.
+ public MemberSerialization MemberSerialization
+ {
+ get { return _memberSerialization; }
+ set { _memberSerialization = value; }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JsonObjectAttribute()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with the specified member serialization.
+ ///
+ /// The member serialization.
+ public JsonObjectAttribute(MemberSerialization memberSerialization)
+ {
+ MemberSerialization = memberSerialization;
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonPropertyAttribute.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonPropertyAttribute.cs
old mode 100755
new mode 100644
index f2161e8..e6049ea
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonPropertyAttribute.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonPropertyAttribute.cs
@@ -1,39 +1,39 @@
-using System;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Instructs the to always serialize the member with the specified name.
- ///
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
- public sealed class JsonPropertyAttribute : Attribute
- {
- private string _propertyName;
-
- ///
- /// Gets or sets the name of the property.
- ///
- /// The name of the property.
- public string PropertyName
- {
- get { return _propertyName; }
- set { _propertyName = value; }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public JsonPropertyAttribute()
- {
- }
-
- ///
- /// Initializes a new instance of the class with the specified name.
- ///
- /// Name of the property.
- public JsonPropertyAttribute(string propertyName)
- {
- _propertyName = propertyName;
- }
- }
+using System;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Instructs the to always serialize the member with the specified name.
+ ///
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
+ public sealed class JsonPropertyAttribute : Attribute
+ {
+ private string _propertyName;
+
+ ///
+ /// Gets or sets the name of the property.
+ ///
+ /// The name of the property.
+ public string PropertyName
+ {
+ get { return _propertyName; }
+ set { _propertyName = value; }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JsonPropertyAttribute()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with the specified name.
+ ///
+ /// Name of the property.
+ public JsonPropertyAttribute(string propertyName)
+ {
+ _propertyName = propertyName;
+ }
+ }
}
\ No newline at end of file
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReader.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReader.cs
old mode 100755
new mode 100644
index 72fe568..f281454
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReader.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReader.cs
@@ -1,404 +1,404 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Xml;
-using System.Globalization;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Utilities;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
- ///
- public abstract class JsonReader : IDisposable
- {
- ///
- /// Specifies the state of the reader.
- ///
- protected enum State
- {
- ///
- /// The Read method has not been called.
- ///
- Start,
- ///
- /// The end of the file has been reached successfully.
- ///
- Complete,
- ///
- /// Reader is at a property.
- ///
- Property,
- ///
- /// Reader is at the start of an object.
- ///
- ObjectStart,
- ///
- /// Reader is in an object.
- ///
- Object,
- ///
- /// Reader is at the start of an array.
- ///
- ArrayStart,
- ///
- /// Reader is in an array.
- ///
- Array,
- ///
- /// The Close method has been called.
- ///
- Closed,
- ///
- /// Reader has just read a value.
- ///
- PostValue,
- ///
- /// Reader is at the start of a constructor.
- ///
- ConstructorStart,
- ///
- /// Reader in a constructor.
- ///
- Constructor,
- ///
- /// An error occurred that prevents the read operation from continuing.
- ///
- Error,
- ///
- /// The end of the file has been reached successfully.
- ///
- Finished
- }
-
- // current Token data
- private JsonToken _token;
- private object _value;
- private Type _valueType;
- private char _quoteChar;
- private State _currentState;
-
- ///
- /// Gets the current reader state.
- ///
- /// The current reader state.
- protected State CurrentState
- {
- get { return _currentState; }
- private set { _currentState = value; }
- }
-
- private int _top;
-
- private List _stack;
-
- ///
- /// Gets the quotation mark character used to enclose the value of a string.
- ///
- public char QuoteChar
- {
- get { return _quoteChar; }
- protected set { _quoteChar = value; }
- }
-
- ///
- /// Gets the type of the current Json token.
- ///
- public JsonToken TokenType
- {
- get { return _token; }
- }
-
- ///
- /// Gets the text value of the current Json token.
- ///
- public object Value
- {
- get { return _value; }
- }
-
- ///
- /// Gets The Common Language Runtime (CLR) type for the current Json token.
- ///
- public Type ValueType
- {
- get { return _valueType; }
- }
-
- ///
- /// Gets the depth of the current token in the JSON document.
- ///
- /// The depth of the current token in the JSON document.
- public int Depth
- {
- get
- {
- int depth = _top - 1;
- if (IsStartToken(TokenType))
- return depth - 1;
- else
- return depth;
- }
- }
-
- ///
- /// Initializes a new instance of the class with the specified .
- ///
- public JsonReader()
- {
- //_testBuffer = new StringBuilder();
- _currentState = State.Start;
- _stack = new List();
- _top = 0;
- Push(JsonTokenType.None);
- }
-
- private void Push(JsonTokenType value)
- {
- _stack.Add(value);
- _top++;
- }
-
- private JsonTokenType Pop()
- {
- JsonTokenType value = Peek();
- _stack.RemoveAt(_stack.Count - 1);
- _top--;
-
- return value;
- }
-
- private JsonTokenType Peek()
- {
- return _stack[_top - 1];
- }
-
- ///
- /// Reads the next Json token from the stream.
- ///
- /// true if the next token was read successfully; false if there are no more tokens to read.
- public abstract bool Read();
-
- ///
- /// Skips the children of the current token.
- ///
- public void Skip()
- {
- if (IsStartToken(TokenType))
- {
- int depth = Depth;
-
- while (Read() && (depth < Depth))
- {
- }
- }
- }
-
- ///
- /// Sets the current token.
- ///
- /// The new token.
- protected void SetToken(JsonToken newToken)
- {
- SetToken(newToken, null);
- }
-
- ///
- /// Sets the current token and value.
- ///
- /// The new token.
- /// The value.
- protected virtual void SetToken(JsonToken newToken, object value)
- {
- _token = newToken;
-
- switch (newToken)
- {
- case JsonToken.StartObject:
- _currentState = State.ObjectStart;
- Push(JsonTokenType.Object);
- break;
- case JsonToken.StartArray:
- _currentState = State.ArrayStart;
- Push(JsonTokenType.Array);
- break;
- case JsonToken.StartConstructor:
- _currentState = State.ConstructorStart;
- Push(JsonTokenType.Constructor);
- break;
- case JsonToken.EndObject:
- ValidateEnd(JsonToken.EndObject);
- _currentState = State.PostValue;
- break;
- case JsonToken.EndArray:
- ValidateEnd(JsonToken.EndArray);
- _currentState = State.PostValue;
- break;
- case JsonToken.EndConstructor:
- ValidateEnd(JsonToken.EndConstructor);
- _currentState = State.PostValue;
- break;
- case JsonToken.PropertyName:
- _currentState = State.Property;
- Push(JsonTokenType.Property);
- break;
- case JsonToken.Undefined:
- case JsonToken.Integer:
- case JsonToken.Float:
- case JsonToken.Boolean:
- case JsonToken.Null:
- case JsonToken.Date:
- case JsonToken.String:
- _currentState = State.PostValue;
- break;
- }
-
- JsonTokenType current = Peek();
- if (current == JsonTokenType.Property && _currentState == State.PostValue)
- Pop();
-
- if (value != null)
- {
- _value = value;
- _valueType = value.GetType();
- }
- else
- {
- _value = null;
- _valueType = null;
- }
- }
-
- private void ValidateEnd(JsonToken endToken)
- {
- JsonTokenType currentObject = Pop();
-
- if (GetTypeForCloseToken(endToken) != currentObject)
- throw new JsonReaderException("JsonToken {0} is not valid for closing JsonType {1}.".FormatWith(CultureInfo.InvariantCulture, endToken, currentObject));
- }
-
- ///
- /// Sets the state based on current token type.
- ///
- protected void SetStateBasedOnCurrent()
- {
- JsonTokenType currentObject = Peek();
-
- switch (currentObject)
- {
- case JsonTokenType.Object:
- _currentState = State.Object;
- break;
- case JsonTokenType.Array:
- _currentState = State.Array;
- break;
- case JsonTokenType.Constructor:
- _currentState = State.Constructor;
- break;
- case JsonTokenType.None:
- _currentState = State.Finished;
- break;
- default:
- throw new JsonReaderException("While setting the reader state back to current object an unexpected JsonType was encountered: " + currentObject);
- }
- }
-
- private bool IsStartToken(JsonToken token)
- {
- switch (token)
- {
- case JsonToken.StartObject:
- case JsonToken.StartArray:
- case JsonToken.StartConstructor:
- case JsonToken.PropertyName:
- return true;
- case JsonToken.None:
- case JsonToken.Comment:
- case JsonToken.Integer:
- case JsonToken.Float:
- case JsonToken.String:
- case JsonToken.Boolean:
- case JsonToken.Null:
- case JsonToken.Undefined:
- case JsonToken.EndObject:
- case JsonToken.EndArray:
- case JsonToken.EndConstructor:
- case JsonToken.Date:
- return false;
- default:
- throw new ArgumentOutOfRangeException("token", token, "Unexpected JsonToken value.");
- }
- }
-
- private JsonTokenType GetTypeForCloseToken(JsonToken token)
- {
- switch (token)
- {
- case JsonToken.EndObject:
- return JsonTokenType.Object;
- case JsonToken.EndArray:
- return JsonTokenType.Array;
- case JsonToken.EndConstructor:
- return JsonTokenType.Constructor;
- default:
- throw new JsonReaderException("Not a valid close JsonToken: " + token);
- }
- }
-
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///
- void IDisposable.Dispose()
- {
- Dispose(true);
- }
-
- ///
- /// Releases unmanaged and - optionally - managed resources
- ///
- /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
- protected virtual void Dispose(bool disposing)
- {
- if (_currentState != State.Closed && disposing)
- Close();
- }
-
- ///
- /// Changes the to Closed.
- ///
- public virtual void Close()
- {
- _currentState = State.Closed;
- _token = JsonToken.None;
- _value = null;
- _valueType = null;
- }
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Xml;
+using System.Globalization;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
+ ///
+ public abstract class JsonReader : IDisposable
+ {
+ ///
+ /// Specifies the state of the reader.
+ ///
+ protected enum State
+ {
+ ///
+ /// The Read method has not been called.
+ ///
+ Start,
+ ///
+ /// The end of the file has been reached successfully.
+ ///
+ Complete,
+ ///
+ /// Reader is at a property.
+ ///
+ Property,
+ ///
+ /// Reader is at the start of an object.
+ ///
+ ObjectStart,
+ ///
+ /// Reader is in an object.
+ ///
+ Object,
+ ///
+ /// Reader is at the start of an array.
+ ///
+ ArrayStart,
+ ///
+ /// Reader is in an array.
+ ///
+ Array,
+ ///
+ /// The Close method has been called.
+ ///
+ Closed,
+ ///
+ /// Reader has just read a value.
+ ///
+ PostValue,
+ ///
+ /// Reader is at the start of a constructor.
+ ///
+ ConstructorStart,
+ ///
+ /// Reader in a constructor.
+ ///
+ Constructor,
+ ///
+ /// An error occurred that prevents the read operation from continuing.
+ ///
+ Error,
+ ///
+ /// The end of the file has been reached successfully.
+ ///
+ Finished
+ }
+
+ // current Token data
+ private JsonToken _token;
+ private object _value;
+ private Type _valueType;
+ private char _quoteChar;
+ private State _currentState;
+
+ ///
+ /// Gets the current reader state.
+ ///
+ /// The current reader state.
+ protected State CurrentState
+ {
+ get { return _currentState; }
+ private set { _currentState = value; }
+ }
+
+ private int _top;
+
+ private List _stack;
+
+ ///
+ /// Gets the quotation mark character used to enclose the value of a string.
+ ///
+ public char QuoteChar
+ {
+ get { return _quoteChar; }
+ protected set { _quoteChar = value; }
+ }
+
+ ///
+ /// Gets the type of the current Json token.
+ ///
+ public JsonToken TokenType
+ {
+ get { return _token; }
+ }
+
+ ///
+ /// Gets the text value of the current Json token.
+ ///
+ public object Value
+ {
+ get { return _value; }
+ }
+
+ ///
+ /// Gets The Common Language Runtime (CLR) type for the current Json token.
+ ///
+ public Type ValueType
+ {
+ get { return _valueType; }
+ }
+
+ ///
+ /// Gets the depth of the current token in the JSON document.
+ ///
+ /// The depth of the current token in the JSON document.
+ public int Depth
+ {
+ get
+ {
+ int depth = _top - 1;
+ if (IsStartToken(TokenType))
+ return depth - 1;
+ else
+ return depth;
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the class with the specified .
+ ///
+ public JsonReader()
+ {
+ //_testBuffer = new StringBuilder();
+ _currentState = State.Start;
+ _stack = new List();
+ _top = 0;
+ Push(JsonTokenType.None);
+ }
+
+ private void Push(JsonTokenType value)
+ {
+ _stack.Add(value);
+ _top++;
+ }
+
+ private JsonTokenType Pop()
+ {
+ JsonTokenType value = Peek();
+ _stack.RemoveAt(_stack.Count - 1);
+ _top--;
+
+ return value;
+ }
+
+ private JsonTokenType Peek()
+ {
+ return _stack[_top - 1];
+ }
+
+ ///
+ /// Reads the next Json token from the stream.
+ ///
+ /// true if the next token was read successfully; false if there are no more tokens to read.
+ public abstract bool Read();
+
+ ///
+ /// Skips the children of the current token.
+ ///
+ public void Skip()
+ {
+ if (IsStartToken(TokenType))
+ {
+ int depth = Depth;
+
+ while (Read() && (depth < Depth))
+ {
+ }
+ }
+ }
+
+ ///
+ /// Sets the current token.
+ ///
+ /// The new token.
+ protected void SetToken(JsonToken newToken)
+ {
+ SetToken(newToken, null);
+ }
+
+ ///
+ /// Sets the current token and value.
+ ///
+ /// The new token.
+ /// The value.
+ protected virtual void SetToken(JsonToken newToken, object value)
+ {
+ _token = newToken;
+
+ switch (newToken)
+ {
+ case JsonToken.StartObject:
+ _currentState = State.ObjectStart;
+ Push(JsonTokenType.Object);
+ break;
+ case JsonToken.StartArray:
+ _currentState = State.ArrayStart;
+ Push(JsonTokenType.Array);
+ break;
+ case JsonToken.StartConstructor:
+ _currentState = State.ConstructorStart;
+ Push(JsonTokenType.Constructor);
+ break;
+ case JsonToken.EndObject:
+ ValidateEnd(JsonToken.EndObject);
+ _currentState = State.PostValue;
+ break;
+ case JsonToken.EndArray:
+ ValidateEnd(JsonToken.EndArray);
+ _currentState = State.PostValue;
+ break;
+ case JsonToken.EndConstructor:
+ ValidateEnd(JsonToken.EndConstructor);
+ _currentState = State.PostValue;
+ break;
+ case JsonToken.PropertyName:
+ _currentState = State.Property;
+ Push(JsonTokenType.Property);
+ break;
+ case JsonToken.Undefined:
+ case JsonToken.Integer:
+ case JsonToken.Float:
+ case JsonToken.Boolean:
+ case JsonToken.Null:
+ case JsonToken.Date:
+ case JsonToken.String:
+ _currentState = State.PostValue;
+ break;
+ }
+
+ JsonTokenType current = Peek();
+ if (current == JsonTokenType.Property && _currentState == State.PostValue)
+ Pop();
+
+ if (value != null)
+ {
+ _value = value;
+ _valueType = value.GetType();
+ }
+ else
+ {
+ _value = null;
+ _valueType = null;
+ }
+ }
+
+ private void ValidateEnd(JsonToken endToken)
+ {
+ JsonTokenType currentObject = Pop();
+
+ if (GetTypeForCloseToken(endToken) != currentObject)
+ throw new JsonReaderException("JsonToken {0} is not valid for closing JsonType {1}.".FormatWith(CultureInfo.InvariantCulture, endToken, currentObject));
+ }
+
+ ///
+ /// Sets the state based on current token type.
+ ///
+ protected void SetStateBasedOnCurrent()
+ {
+ JsonTokenType currentObject = Peek();
+
+ switch (currentObject)
+ {
+ case JsonTokenType.Object:
+ _currentState = State.Object;
+ break;
+ case JsonTokenType.Array:
+ _currentState = State.Array;
+ break;
+ case JsonTokenType.Constructor:
+ _currentState = State.Constructor;
+ break;
+ case JsonTokenType.None:
+ _currentState = State.Finished;
+ break;
+ default:
+ throw new JsonReaderException("While setting the reader state back to current object an unexpected JsonType was encountered: " + currentObject);
+ }
+ }
+
+ private bool IsStartToken(JsonToken token)
+ {
+ switch (token)
+ {
+ case JsonToken.StartObject:
+ case JsonToken.StartArray:
+ case JsonToken.StartConstructor:
+ case JsonToken.PropertyName:
+ return true;
+ case JsonToken.None:
+ case JsonToken.Comment:
+ case JsonToken.Integer:
+ case JsonToken.Float:
+ case JsonToken.String:
+ case JsonToken.Boolean:
+ case JsonToken.Null:
+ case JsonToken.Undefined:
+ case JsonToken.EndObject:
+ case JsonToken.EndArray:
+ case JsonToken.EndConstructor:
+ case JsonToken.Date:
+ return false;
+ default:
+ throw new ArgumentOutOfRangeException("token", token, "Unexpected JsonToken value.");
+ }
+ }
+
+ private JsonTokenType GetTypeForCloseToken(JsonToken token)
+ {
+ switch (token)
+ {
+ case JsonToken.EndObject:
+ return JsonTokenType.Object;
+ case JsonToken.EndArray:
+ return JsonTokenType.Array;
+ case JsonToken.EndConstructor:
+ return JsonTokenType.Constructor;
+ default:
+ throw new JsonReaderException("Not a valid close JsonToken: " + token);
+ }
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ void IDisposable.Dispose()
+ {
+ Dispose(true);
+ }
+
+ ///
+ /// Releases unmanaged and - optionally - managed resources
+ ///
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_currentState != State.Closed && disposing)
+ Close();
+ }
+
+ ///
+ /// Changes the to Closed.
+ ///
+ public virtual void Close()
+ {
+ _currentState = State.Closed;
+ _token = JsonToken.None;
+ _value = null;
+ _valueType = null;
+ }
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReaderException.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReaderException.cs
old mode 100755
new mode 100644
index 711c450..9940c67
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReaderException.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonReaderException.cs
@@ -1,65 +1,65 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Newtonsoft.Json
-{
- ///
- /// The exception thrown when an error occurs while reading Json text.
- ///
- public class JsonReaderException : Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public JsonReaderException()
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with a specified error message.
- ///
- /// The error message that explains the reason for the exception.
- public JsonReaderException(string message)
- : base(message)
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with a specified error message and a reference to the inner exception that is the cause of this exception.
- ///
- /// The error message that explains the reason for the exception.
- /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
- public JsonReaderException(string message, Exception innerException)
- : base(message, innerException)
- {
- }
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// The exception thrown when an error occurs while reading Json text.
+ ///
+ public class JsonReaderException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JsonReaderException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public JsonReaderException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message and a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
+ public JsonReaderException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializationException.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializationException.cs
old mode 100755
new mode 100644
index 758caa4..bec2635
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializationException.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializationException.cs
@@ -1,65 +1,65 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Newtonsoft.Json
-{
- ///
- /// The exception thrown when an error occurs during Json serialization or deserialization.
- ///
- public class JsonSerializationException : Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public JsonSerializationException()
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with a specified error message.
- ///
- /// The error message that explains the reason for the exception.
- public JsonSerializationException(string message)
- : base(message)
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with a specified error message and a reference to the inner exception that is the cause of this exception.
- ///
- /// The error message that explains the reason for the exception.
- /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
- public JsonSerializationException(string message, Exception innerException)
- : base(message, innerException)
- {
- }
- }
-}
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// The exception thrown when an error occurs during Json serialization or deserialization.
+ ///
+ public class JsonSerializationException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JsonSerializationException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public JsonSerializationException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message and a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
+ public JsonSerializationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializer.cs b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializer.cs
old mode 100755
new mode 100644
index a182701..12afeae
--- a/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializer.cs
+++ b/worldpay-lib-dotnet-2-0/Newtonsoft.Json/JsonSerializer.cs
@@ -1,830 +1,830 @@
-#region License
-// Copyright (c) 2007 James Newton-King
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Collections;
-using System.Linq;
-using System.Reflection;
-using System.ComponentModel;
-using Newtonsoft.Json.Utilities;
-using System.Globalization;
-using Newtonsoft.Json.Linq;
-using System.Collections.ObjectModel;
-
-namespace Newtonsoft.Json
-{
- ///
- /// Serializes and deserializes objects into and from the Json format.
- /// The enables you to control how objects are encoded into Json.
- ///
- public class JsonSerializer
- {
- private ReferenceLoopHandling _referenceLoopHandling;
- private MissingMemberHandling _missingMemberHandling;
- private ObjectCreationHandling _objectCreationHandling;
- private NullValueHandling _nullValueHandling;
- private int _level;
- private JsonConverterCollection _converters;
- private Dictionary _typeMemberMappings;
-
- ///
- /// Get or set how reference loops (e.g. a class referencing itself) is handled.
- ///
- public ReferenceLoopHandling ReferenceLoopHandling
- {
- get { return _referenceLoopHandling; }
- set
- {
- if (value < ReferenceLoopHandling.Error || value > ReferenceLoopHandling.Serialize)
- throw new ArgumentOutOfRangeException("value");
-
- _referenceLoopHandling = value;
- }
- }
-
- ///
- /// Get or set how missing members (e.g. JSON contains a property that isn't a member on the object) are handled during deserialization.
- ///
- public MissingMemberHandling MissingMemberHandling
- {
- get { return _missingMemberHandling; }
- set
- {
- if (value < MissingMemberHandling.Error || value > MissingMemberHandling.Ignore)
- throw new ArgumentOutOfRangeException("value");
-
- _missingMemberHandling = value;
- }
- }
-
- ///
- /// Get or set how null values are handled during serialization and deserialization.
- ///
- public NullValueHandling NullValueHandling
- {
- get { return _nullValueHandling; }
- set
- {
- if (value < NullValueHandling.Include || value > NullValueHandling.Ignore)
- throw new ArgumentOutOfRangeException("value");
-
- _nullValueHandling = value;
- }
- }
-
- ///
- /// Gets or sets how objects are created during deserialization.
- ///
- /// The object creation handling.
- public ObjectCreationHandling ObjectCreationHandling
- {
- get { return _objectCreationHandling; }
- set
- {
- if (value < ObjectCreationHandling.Auto || value > ObjectCreationHandling.Replace)
- throw new ArgumentOutOfRangeException("value");
-
- _objectCreationHandling = value;
- }
- }
-
- ///
- /// Gets a collection that will be used during serialization.
- ///
- /// Collection that will be used during serialization.
- public JsonConverterCollection Converters
- {
- get
- {
- if (_converters == null)
- _converters = new JsonConverterCollection();
-
- return _converters;
- }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public JsonSerializer()
- {
- _referenceLoopHandling = ReferenceLoopHandling.Error;
- _missingMemberHandling = MissingMemberHandling.Error;
- _nullValueHandling = NullValueHandling.Include;
- _objectCreationHandling = ObjectCreationHandling.Auto;
- }
-
- #region Deserialize
- ///
- /// Deserializes the Json structure contained by the specified .
- ///
- /// The that contains the Json structure to deserialize.
- /// The being deserialized.
- public object Deserialize(JsonReader reader)
- {
- return Deserialize(reader, null);
- }
-
- ///
- /// Deserializes the Json structure contained by the specified
- /// into an instance of the specified type.
- ///
- /// The containing the object.
- /// The of object being deserialized.
- /// The instance of being deserialized.
- public object Deserialize(JsonReader reader, Type objectType)
- {
- if (reader == null)
- throw new ArgumentNullException("reader");
-
- if (!reader.Read())
- return null;
-
- if (objectType != null)
- return CreateObject(reader, objectType, null);
- else
- return CreateJToken(reader);
- }
-
- ///
- /// Deserializes the Json structure contained by the specified
- /// into an instance of the specified type.
- ///
- /// The containing the object.
- /// The of object being deserialized.
- /// The instance of being deserialized.
- public object Deserialize(StringReader reader, Type objectType)
- {
- return Deserialize(new JsonTextReader(reader), objectType);
- }
-
- private JToken CreateJToken(JsonReader reader)
- {
- JToken token;
- using (JsonTokenWriter writer = new JsonTokenWriter())
- {
- writer.WriteToken(reader);
- token = writer.Token;
- }
-
- return token;
- }
-
- private object CreateObject(JsonReader reader, Type objectType, object existingValue)
- {
- _level++;
-
- object value;
- JsonConverter converter;
-
- if (HasMatchingConverter(objectType, out converter))
- {
- return converter.ReadJson(reader, objectType);
- }
- else
- {
- switch (reader.TokenType)
- {
- // populate a typed object or generic dictionary/array
- // depending upon whether an objectType was supplied
- case JsonToken.StartObject:
- if (objectType == null)
- {
- value = CreateJToken(reader);
- }
- else if (typeof(IDictionary).IsAssignableFrom(objectType) || ReflectionUtils.IsSubClass(objectType, typeof(IDictionary<,>)))
- {
- if (existingValue == null)
- value = CreateAndPopulateDictionary(reader, objectType);
- else
- value = PopulateDictionary(CollectionUtils.CreateDictionaryWrapper(existingValue), reader);
- }
- else
- {
- if (existingValue == null)
- value = CreateAndPopulateObject(reader, objectType);
- else
- value = PopulateObject(existingValue, reader, objectType);
- }
- break;
- case JsonToken.StartArray:
- if (objectType != null)
- {
- if (existingValue == null)
- value = CreateAndPopulateList(reader, objectType);
- else
- value = PopulateList(CollectionUtils.CreateListWrapper(existingValue), ReflectionUtils.GetListItemType(objectType), reader);
- }
- else
- {
- value = CreateJToken(reader);
- }
- break;
- case JsonToken.Integer:
- case JsonToken.Float:
- case JsonToken.String:
- case JsonToken.Boolean:
- case JsonToken.Date:
- value = EnsureType(reader.Value, objectType);
- break;
- case JsonToken.StartConstructor:
- case JsonToken.EndConstructor:
- string constructorName = reader.Value.ToString();
-
- value = constructorName;
- break;
- case JsonToken.Null:
- case JsonToken.Undefined:
- if (objectType == typeof(DBNull))
- value = DBNull.Value;
- else
- value = null;
- break;
- default:
- throw new JsonSerializationException("Unexpected token while deserializing object: " + reader.TokenType);
- }
- }
-
- _level--;
-
- return value;
- }
-
- private object EnsureType(object value, Type targetType)
- {
- // do something about null value when the targetType is a valuetype?
- if (value == null)
- return null;
-
- if (targetType == null)
- return value;
-
- Type valueType = value.GetType();
-
- // type of value and type of target don't match
- // attempt to convert value's type to target's type
- if (valueType != targetType)
- {
- TypeConverter targetConverter = TypeDescriptor.GetConverter(targetType);
-
- if (!targetConverter.CanConvertFrom(valueType))
- {
- if (targetConverter.CanConvertFrom(typeof(string)))
- {
- string valueString = TypeDescriptor.GetConverter(value).ConvertToInvariantString(value);
-
- return targetConverter.ConvertFromInvariantString(valueString);
- }
-
- if (targetType == typeof(DateTimeOffset) && value is DateTime)
- return new DateTimeOffset((DateTime)value);
-
- if (!targetType.IsAssignableFrom(valueType))
- throw new InvalidOperationException("Cannot convert object of type '{0}' to type '{1}'".FormatWith(CultureInfo.InvariantCulture, value.GetType(), targetType));
-
- return value;
- }
-
- return targetConverter.ConvertFrom(null, CultureInfo.InvariantCulture, value);
- }
- else
- {
- return value;
- }
- }
-
- private MemberMappingCollection GetMemberMappings(Type objectType)
- {
- if (_typeMemberMappings == null)
- _typeMemberMappings = new Dictionary();
-
- MemberMappingCollection memberMappings;
-
- if (_typeMemberMappings.TryGetValue(objectType, out memberMappings))
- return memberMappings;
-
- memberMappings = CreateMemberMappings(objectType);
- _typeMemberMappings[objectType] = memberMappings;
-
- return memberMappings;
- }
-
- private MemberMappingCollection CreateMemberMappings(Type objectType)
- {
- MemberSerialization memberSerialization = GetObjectMemberSerialization(objectType);
-
- List members = GetSerializableMembers(objectType);
- if (members == null)
- throw new JsonSerializationException("Null collection of seralizable members returned.");
-
- MemberMappingCollection memberMappings = new MemberMappingCollection();
-
- foreach (MemberInfo member in members)
- {
- JsonPropertyAttribute propertyAttribute = ReflectionUtils.GetAttribute(member, true);
- bool hasIgnoreAttribute = member.IsDefined(typeof(JsonIgnoreAttribute), true);
-
- string mappedName = (propertyAttribute != null && propertyAttribute.PropertyName != null)
- ? propertyAttribute.PropertyName
- : member.Name;
-
- bool ignored = (hasIgnoreAttribute
- || (memberSerialization == MemberSerialization.OptIn && propertyAttribute == null));
-
- bool readable = ReflectionUtils.CanReadMemberValue(member);
- bool writable = ReflectionUtils.CanSetMemberValue(member);
- MemberMapping memberMapping = new MemberMapping(mappedName, member, ignored, readable, writable);
-
- memberMappings.AddMapping(memberMapping);
- }
-
- return memberMappings;
- }
-
- ///
- /// Gets the serializable members for the given .
- ///
- /// The object to get seralizable members for.
- /// Seralizable members for the given type.
- protected virtual List GetSerializableMembers(Type objectType)
- {
- return ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.Instance);
- }
-
- private static MemberSerialization GetObjectMemberSerialization(Type objectType)
- {
- JsonObjectAttribute objectAttribute = ReflectionUtils.GetAttribute(objectType, true);
-
- if (objectAttribute == null)
- return MemberSerialization.OptOut;
- else
- return objectAttribute.MemberSerialization;
- }
-
- private void SetObjectMember(JsonReader reader, object target, Type targetType, string memberName)
- {
- if (!reader.Read())
- throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
-
- MemberMappingCollection memberMappings = GetMemberMappings(targetType);
- Type memberType;
- object value;
-
- // test if a member with memberName exists on the type
- // otherwise test if target is a dictionary and assign value with the key if it is
- if (memberMappings.Contains(memberName))
- {
- MemberMapping memberMapping = memberMappings[memberName];
-
- if (memberMapping.Ignored)
- {
- reader.Skip();
- return;
- }
-
- // get the member's underlying type
- memberType = ReflectionUtils.GetMemberUnderlyingType(memberMapping.Member);
- object currentValue = ReflectionUtils.GetMemberValue(memberMapping.Member, target);
-
- bool useExistingValue = (currentValue != null
- && (_objectCreationHandling == ObjectCreationHandling.Auto || _objectCreationHandling == ObjectCreationHandling.Reuse)
- && (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject)
- && (!memberType.IsArray && !ReflectionUtils.IsSubClass(memberType, typeof(ReadOnlyCollection<>))));
-
- if (!memberMapping.Writable && !useExistingValue)
- {
- reader.Skip();
- return;
- }
-
- value = CreateObject(reader, memberType, (useExistingValue) ? currentValue : null);
-
- if (_nullValueHandling == NullValueHandling.Ignore && value == null)
- return;
-
- if (!useExistingValue)
- ReflectionUtils.SetMemberValue(memberMapping.Member, target, value);
- }
- else
- {
- if (_missingMemberHandling == MissingMemberHandling.Error)
- throw new JsonSerializationException("Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, targetType.GetType().Name));
- }
- }
-
- private object CreateAndPopulateDictionary(JsonReader reader, Type objectType)
- {
- IWrappedDictionary dictionary = CollectionUtils.CreateDictionaryWrapper(Activator.CreateInstance(objectType));
- PopulateDictionary(dictionary, reader);
-
- return dictionary.UnderlyingDictionary;
- }
-
- private IDictionary PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader)
- {
- Type dictionaryType = dictionary.UnderlyingDictionary.GetType();
- Type dictionaryKeyType = ReflectionUtils.GetDictionaryKeyType(dictionaryType);
- Type dictionaryValueType = ReflectionUtils.GetDictionaryValueType(dictionaryType);
-
- while (reader.Read())
- {
- switch (reader.TokenType)
- {
- case JsonToken.PropertyName:
- object keyValue = EnsureType(reader.Value, dictionaryKeyType);
- reader.Read();
-
- dictionary.Add(keyValue, CreateObject(reader, dictionaryValueType, null));
- break;
- case JsonToken.EndObject:
- return dictionary;
- default:
- throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
- }
- }
-
- throw new JsonSerializationException("Unexpected end when deserializing object.");
- }
-
- private object CreateAndPopulateList(JsonReader reader, Type objectType)
- {
- return CollectionUtils.CreateAndPopulateList(objectType, l => PopulateList(l, ReflectionUtils.GetListItemType(objectType), reader));
- }
-
- private IList PopulateList(IList list, Type listItemType, JsonReader reader)
- {
- while (reader.Read())
- {
- switch (reader.TokenType)
- {
- case JsonToken.EndArray:
- return list;
- case JsonToken.Comment:
- break;
- default:
- object value = CreateObject(reader, listItemType, null);
-
- list.Add(value);
- break;
- }
- }
-
- throw new JsonSerializationException("Unexpected end when deserializing array.");
- }
-
- private object CreateAndPopulateObject(JsonReader reader, Type objectType)
- {
- object newObject;
-
- if (ReflectionUtils.HasDefaultConstructor(objectType))
- {
- newObject = Activator.CreateInstance(objectType);
-
- PopulateObject(newObject, reader, objectType);
- return newObject;
- }
- else
- {
- ConstructorInfo c = objectType.GetConstructors(BindingFlags.Public | BindingFlags.Instance).SingleOrDefault();
-
- if (c == null)
- throw new JsonSerializationException("Could not find a public constructor for type {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
-
- IDictionary constructorParameters = c.GetParameters().ToDictionary(p => p, p => (object)null);
-
- bool exit = false;
- while (!exit && reader.Read())
- {
- switch (reader.TokenType)
- {
- case JsonToken.PropertyName:
- string memberName = reader.Value.ToString();
- ParameterInfo matchingConstructorParameter = constructorParameters
- .Where(kv => kv.Key.Name == memberName)
- .Select(kv => kv.Key)
- .SingleOrDefault();
-
- if (!reader.Read())
- throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
-
- if (matchingConstructorParameter != null)
- constructorParameters[matchingConstructorParameter] = CreateObject(reader, matchingConstructorParameter.ParameterType, null);
-
- break;
- case JsonToken.EndObject:
- exit = true;
- break;
- default:
- throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
- }
- }
-
- newObject = Activator.CreateInstance(objectType, constructorParameters.Values.ToArray());
-
- return newObject;
- }
- }
-
- private object PopulateObject(object newObject, JsonReader reader, Type objectType)
- {
- while (reader.Read())
- {
- switch (reader.TokenType)
- {
- case JsonToken.PropertyName:
- string memberName = reader.Value.ToString();
-
- SetObjectMember(reader, newObject, objectType, memberName);
- break;
- case JsonToken.EndObject:
- return newObject;
- default:
- throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
- }
- }
-
- throw new JsonSerializationException("Unexpected end when deserializing object.");
- }
- #endregion
-
- #region Serialize
- ///
- /// Serializes the specified and writes the Json structure
- /// to a Stream using the specified .
- ///
- /// The used to write the Json structure.
- /// The to serialize.
- public void Serialize(TextWriter textWriter, object value)
- {
- Serialize(new JsonTextWriter(textWriter), value);
- }
-
- ///
- /// Serializes the specified and writes the Json structure
- /// to a Stream using the specified .
- ///
- /// The used to write the Json structure.
- /// The to serialize.
- public void Serialize(JsonWriter jsonWriter, object value)
- {
- if (jsonWriter == null)
- throw new ArgumentNullException("jsonWriter");
-
- if (value is JToken)
- ((JToken)value).WriteTo(jsonWriter, (_converters != null) ? _converters.ToArray() : null);
- else
- SerializeValue(jsonWriter, value);
- }
-
-
- private void SerializeValue(JsonWriter writer, object value)
- {
- JsonConverter converter;
-
- if (value == null)
- {
- writer.WriteNull();
- }
- else if (HasMatchingConverter(value.GetType(), out converter))
- {
- converter.WriteJson(writer, value);
- }
- else if (value is IConvertible)
- {
- IConvertible convertible = value as IConvertible;
-
- switch (convertible.GetTypeCode())
- {
- case TypeCode.String:
- writer.WriteValue((string)convertible);
- break;
- case TypeCode.Char:
- writer.WriteValue((char)convertible);
- break;
- case TypeCode.Boolean:
- writer.WriteValue((bool)convertible);
- break;
- case TypeCode.SByte:
- writer.WriteValue((sbyte)convertible);
- break;
- case TypeCode.Int16:
- writer.WriteValue((short)convertible);
- break;
- case TypeCode.UInt16:
- writer.WriteValue((ushort)convertible);
- break;
- case TypeCode.Int32:
- writer.WriteValue((int)convertible);
- break;
- case TypeCode.Byte:
- writer.WriteValue((byte)convertible);
- break;
- case TypeCode.UInt32:
- writer.WriteValue((uint)convertible);
- break;
- case TypeCode.Int64:
- writer.WriteValue((long)convertible);
- break;
- case TypeCode.UInt64:
- writer.WriteValue((ulong)convertible);
- break;
- case TypeCode.Single:
- writer.WriteValue((float)convertible);
- break;
- case TypeCode.Double:
- writer.WriteValue((double)convertible);
- break;
- case TypeCode.DateTime:
- writer.WriteValue((DateTime)convertible);
- break;
- case TypeCode.Decimal:
- writer.WriteValue((decimal)convertible);
- break;
- case TypeCode.DBNull:
- writer.WriteNull();
- break;
- default:
- SerializeObject(writer, value);
- break;
- }
- }
- else if (value is DateTimeOffset)
- {
- writer.WriteValue((DateTimeOffset)value);
- }
- else if (value is IList)
- {
- SerializeList(writer, (IList)value);
- }
- else if (value is IDictionary)
- {
- SerializeDictionary(writer, (IDictionary)value);
- }
- else if (value is ICollection)
- {
- SerializeCollection(writer, (ICollection)value);
- }
- else if (value is IEnumerable)
- {
- SerializeEnumerable(writer, (IEnumerable)value);
- }
- else if (value is Identifier)
- {
- writer.WriteRaw(value.ToString());
- }
- else
- {
- SerializeObject(writer, value);
- }
- }
-
- private bool HasMatchingConverter(Type type, out JsonConverter matchingConverter)
- {
- return HasMatchingConverter(_converters, type, out matchingConverter);
- }
-
- internal static bool HasMatchingConverter(IList converters, Type type, out JsonConverter matchingConverter)
- {
- if (converters != null)
- {
- for (int i = 0; i < converters.Count; i++)
- {
- JsonConverter converter = converters[i];
-
- if (converter.CanConvert(type))
- {
- matchingConverter = converter;
- return true;
- }
- }
- }
-
- matchingConverter = null;
- return false;
- }
-
- private void WriteMemberInfoProperty(JsonWriter writer, object value, MemberInfo member, string propertyName)
- {
- if (!ReflectionUtils.IsIndexedProperty(member))
- {
- object memberValue = ReflectionUtils.GetMemberValue(member, value);
-
- if (_nullValueHandling == NullValueHandling.Ignore && memberValue == null)
- return;
-
- if (writer.SerializeStack.IndexOf(memberValue) != -1)
- {
- switch (_referenceLoopHandling)
- {
- case ReferenceLoopHandling.Error:
- throw new JsonSerializationException("Self referencing loop");
- case ReferenceLoopHandling.Ignore:
- // return from method
- return;
- case ReferenceLoopHandling.Serialize:
- // continue
- break;
- default:
- throw new InvalidOperationException("Unexpected ReferenceLoopHandling value: '{0}'".FormatWith(CultureInfo.InvariantCulture, _referenceLoopHandling));
- }
- }
-
- writer.WritePropertyName(propertyName ?? member.Name);
- SerializeValue(writer, memberValue);
- }
- }
-
- private void SerializeObject(JsonWriter writer, object value)
- {
- Type objectType = value.GetType();
-
- TypeConverter converter = TypeDescriptor.GetConverter(objectType);
-
- // use the objectType's TypeConverter if it has one and can convert to a string
- if (converter != null && !(converter is ComponentConverter) && converter.GetType() != typeof(TypeConverter))
- {
- if (converter.CanConvertTo(typeof(string)))
- {
- writer.WriteValue(converter.ConvertToInvariantString(value));
- return;
- }
- }
-
- writer.SerializeStack.Add(value);
-
- writer.WriteStartObject();
-
- MemberMappingCollection memberMappings = GetMemberMappings(objectType);
-
- foreach (MemberMapping memberMapping in memberMappings)
- {
- if (!memberMapping.Ignored && memberMapping.Readable)
- WriteMemberInfoProperty(writer, value, memberMapping.Member, memberMapping.MappingName);
- }
-
- writer.WriteEndObject();
-
- writer.SerializeStack.Remove(value);
- }
-
- private void SerializeEnumerable(JsonWriter writer, IEnumerable values)
- {
- SerializeList(writer, values.Cast