-XML documentation

-Fixed culture warnings
This commit is contained in:
JamesNK
2009-12-07 22:39:10 +00:00
parent 5cc46295c8
commit 30322a49d2
21 changed files with 330 additions and 37 deletions
+37 -13
View File
@@ -34,19 +34,9 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Bson
{
internal enum BsonReaderState
{
Normal,
ReferenceStart,
ReferenceRef,
ReferenceId,
CodeWScopeStart,
CodeWScopeCode,
CodeWScopeScope,
CodeWScopeScopeObject,
CodeWScopeScopeEnd
}
/// <summary>
/// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
/// </summary>
public class BsonReader : JsonReader
{
private readonly BinaryReader _reader;
@@ -56,6 +46,19 @@ namespace Newtonsoft.Json.Bson
private BsonType _currentElementType;
private BsonReaderState _bsonReaderState;
private enum BsonReaderState
{
Normal,
ReferenceStart,
ReferenceRef,
ReferenceId,
CodeWScopeStart,
CodeWScopeCode,
CodeWScopeScope,
CodeWScopeScopeObject,
CodeWScopeScopeEnd
}
private class ContainerContext
{
public JTokenType Type { get; private set; }
@@ -79,10 +82,19 @@ namespace Newtonsoft.Json.Bson
}
}
/// <summary>
/// Initializes a new instance of the <see cref="BsonReader"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
public BsonReader(Stream stream) : this(stream, false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BsonReader"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="rootTypeIsArray">if set to <c>true</c> the root object will be read as a JSON array.</param>
public BsonReader(Stream stream, bool rootTypeIsArray)
{
ValidationUtils.ArgumentNotNull(stream, "stream");
@@ -98,6 +110,12 @@ namespace Newtonsoft.Json.Bson
return elementName;
}
/// <summary>
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
/// </summary>
/// <returns>
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
/// </returns>
public override byte[] ReadAsBytes()
{
Read();
@@ -107,6 +125,12 @@ namespace Newtonsoft.Json.Bson
return (byte[])Value;
}
/// <summary>
/// Reads the next JSON token from the stream.
/// </summary>
/// <returns>
/// true if the next token was read successfully; false if there are no more tokens to read.
/// </returns>
public override bool Read()
{
try
+19 -9
View File
@@ -24,28 +24,34 @@
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq;
using System.Globalization;
namespace Newtonsoft.Json.Bson
{
/// <summary>
/// Represents a writer that provides a fast, non-cached, forward-only way of generating Json data.
/// </summary>
public class BsonWriter : JTokenWriter
{
private readonly Stream _stream;
private readonly BinaryWriter _writer;
/// <summary>
/// Initializes a new instance of the <see cref="BsonWriter"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
public BsonWriter(Stream stream)
{
ValidationUtils.ArgumentNotNull(stream, "stream");
_stream = stream;
_writer = new BinaryWriter(stream);
}
/// <summary>
/// Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
/// </summary>
public override void Flush()
{
_writer.Flush();
@@ -76,7 +82,7 @@ namespace Newtonsoft.Json.Bson
foreach (JToken c in t)
{
_writer.Write((sbyte)GetTypeNumber(c));
WriteString(index.ToString());
WriteString(index.ToString(CultureInfo.InvariantCulture));
WriteToken(c);
index++;
}
@@ -84,10 +90,10 @@ namespace Newtonsoft.Json.Bson
}
break;
case JTokenType.Integer:
_writer.Write(Convert.ToInt32(((JValue)t).Value));
_writer.Write(Convert.ToInt32(((JValue)t).Value, CultureInfo.InvariantCulture));
break;
case JTokenType.Float:
_writer.Write(Convert.ToDouble(((JValue)t).Value));
_writer.Write(Convert.ToDouble(((JValue)t).Value, CultureInfo.InvariantCulture));
break;
case JTokenType.String:
WriteStringWithLength((string)t);
@@ -201,7 +207,7 @@ namespace Newtonsoft.Json.Bson
foreach (JToken c in t)
{
bases += 1;
bases += CalculateSize(index.ToString());
bases += CalculateSize(index.ToString(CultureInfo.InvariantCulture));
bases += CalculateSize(c);
index++;
}
@@ -243,6 +249,10 @@ namespace Newtonsoft.Json.Bson
}
}
/// <summary>
/// Writes the end.
/// </summary>
/// <param name="token">The token.</param>
protected override void WriteEnd(JsonToken token)
{
base.WriteEnd(token);
@@ -32,8 +32,17 @@ using System.Text;
namespace Newtonsoft.Json.Converters
{
/// <summary>
/// Converts a <see cref="DataSet"/> to and from JSON.
/// </summary>
public class DataSetConverter : JsonConverter
{
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
DataSet dataSet = (DataSet)value;
@@ -52,6 +61,13 @@ namespace Newtonsoft.Json.Converters
writer.WriteEndObject();
}
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>The object value.</returns>
public override object ReadJson(JsonReader reader, Type objectType, JsonSerializer serializer)
{
DataSet ds = new DataSet();
@@ -71,6 +87,13 @@ namespace Newtonsoft.Json.Converters
return ds;
}
/// <summary>
/// Determines whether this instance can convert the specified value type.
/// </summary>
/// <param name="valueType">Type of the value.</param>
/// <returns>
/// <c>true</c> if this instance can convert the specified value type; otherwise, <c>false</c>.
/// </returns>
public override bool CanConvert(Type valueType)
{
return (valueType == typeof(DataSet));
@@ -32,8 +32,17 @@ using System.Data;
namespace Newtonsoft.Json.Converters
{
/// <summary>
/// Converts a <see cref="DataTable"/> to and from JSON.
/// </summary>
public class DataTableConverter : JsonConverter
{
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
DataTable table = (DataTable)value;
@@ -54,6 +63,13 @@ namespace Newtonsoft.Json.Converters
writer.WriteEndArray();
}
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>The object value.</returns>
public override object ReadJson(JsonReader reader, Type objectType, JsonSerializer serializer)
{
DataTable dt;
@@ -123,6 +139,13 @@ namespace Newtonsoft.Json.Converters
}
}
/// <summary>
/// Determines whether this instance can convert the specified value type.
/// </summary>
/// <param name="valueType">Type of the value.</param>
/// <returns>
/// <c>true</c> if this instance can convert the specified value type; otherwise, <c>false</c>.
/// </returns>
public override bool CanConvert(Type valueType)
{
return (valueType == typeof(DataTable));
+4
View File
@@ -204,6 +204,10 @@ namespace Newtonsoft.Json
/// <returns>true if the next token was read successfully; false if there are no more tokens to read.</returns>
public abstract bool Read();
/// <summary>
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
/// </summary>
/// <returns>A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.</returns>
public abstract byte[] ReadAsBytes();
/// <summary>
+6
View File
@@ -327,6 +327,12 @@ namespace Newtonsoft.Json
}
}
/// <summary>
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
/// </summary>
/// <returns>
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
/// </returns>
public override byte[] ReadAsBytes()
{
while (true)
+4
View File
@@ -431,6 +431,10 @@ namespace Newtonsoft.Json
WriteValueInternal(JsonConvert.ToString(value), JsonToken.Date);
}
/// <summary>
/// Writes a <see cref="T:Byte[]"/> value.
/// </summary>
/// <param name="value">The <see cref="T:Byte[]"/> value to write.</param>
public override void WriteValue(byte[] value)
{
base.WriteValue(value);
@@ -304,6 +304,12 @@ namespace Newtonsoft.Json
}
}
/// <summary>
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
/// </summary>
/// <returns>
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
/// </returns>
public override byte[] ReadAsBytes()
{
byte[] data = _reader.ReadAsBytes();
+4
View File
@@ -975,6 +975,10 @@ namespace Newtonsoft.Json
}
#endif
/// <summary>
/// Writes a <see cref="T:Byte[]"/> value.
/// </summary>
/// <param name="value">The <see cref="T:Byte[]"/> value to write.</param>
public virtual void WriteValue(byte[] value)
{
if (value == null)
+31
View File
@@ -742,6 +742,11 @@ namespace Newtonsoft.Json.Linq
return Convert.ToUInt64(v.Value, CultureInfo.InvariantCulture);
}
/// <summary>
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="T:System.Byte[]"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator byte[](JToken value)
{
JValue v = EnsureValue(value);
@@ -987,6 +992,11 @@ namespace Newtonsoft.Json.Linq
return new JValue(value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="T:System.Byte[]"/> to <see cref="Newtonsoft.Json.Linq.JToken"/>.
/// </summary>
/// <param name="value">The value to create a <see cref="JValue"/> from.</param>
/// <returns>The <see cref="JValue"/> initialized with the specified value.</returns>
public static implicit operator JToken(byte[] value)
{
return new JValue(value);
@@ -1123,11 +1133,32 @@ namespace Newtonsoft.Json.Linq
get { return _linePosition ?? 0; }
}
/// <summary>
/// Selects the token that matches the object path.
/// </summary>
/// <param name="path">
/// The object path from the current <see cref="JToken"/> to the <see cref="JToken"/>
/// to be returned. This must be a string of property names or array indexes separated
/// by periods, such as <code>Tables[0].DefaultView[0].Price</code> in C# or
/// <code>Tables(0).DefaultView(0).Price</code> in Visual Basic.
/// </param>
/// <returns>The <see cref="JToken"/> that matches the object path or a null reference if no matching token is found.</returns>
public JToken SelectToken(string path)
{
return SelectToken(path, false);
}
/// <summary>
/// Selects the token that matches the object path.
/// </summary>
/// <param name="path">
/// The object path from the current <see cref="JToken"/> to the <see cref="JToken"/>
/// to be returned. This must be a string of property names or array indexes separated
/// by periods, such as <code>Tables[0].DefaultView[0].Price</code> in C# or
/// <code>Tables(0).DefaultView(0).Price</code> in Visual Basic.
/// </param>
/// <param name="errorWhenNoMatch">A flag to indicate whether an error should be thrown if no token is found.</param>
/// <returns>The <see cref="JToken"/> that matches the object path.</returns>
public JToken SelectToken(string path, bool errorWhenNoMatch)
{
JPath p = new JPath(path);
+6
View File
@@ -28,6 +28,12 @@ namespace Newtonsoft.Json.Linq
_current = token;
}
/// <summary>
/// Reads the next JSON token from the stream as a <see cref="T:Byte[]"/>.
/// </summary>
/// <returns>
/// A <see cref="T:Byte[]"/> or a null reference if the next JSON token is null.
/// </returns>
public override byte[] ReadAsBytes()
{
Read();
+3 -5
View File
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Linq
{
/// <summary>
@@ -91,6 +86,9 @@ namespace Newtonsoft.Json.Linq
/// A raw JSON value.
/// </summary>
Raw,
/// <summary>
/// A collection of bytes value.
/// </summary>
Bytes
}
}
+4
View File
@@ -346,6 +346,10 @@ namespace Newtonsoft.Json.Linq
}
#endif
/// <summary>
/// Writes a <see cref="T:Byte[]"/> value.
/// </summary>
/// <param name="value">The <see cref="T:Byte[]"/> value to write.</param>
public override void WriteValue(byte[] value)
{
base.WriteValue(value);
+12
View File
@@ -1,9 +1,21 @@
namespace Newtonsoft.Json
{
/// <summary>
/// Indicating whether a property is required.
/// </summary>
public enum Required
{
/// <summary>
/// The property is not required. The default state.
/// </summary>
Default,
/// <summary>
/// The property must be defined in JSON but can be a null value.
/// </summary>
AllowNull,
/// <summary>
/// The property must be defined in JSON and cannot be a null value.
/// </summary>
Always
}
}
@@ -1,4 +1,29 @@
#if !PocketPC
#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
#if !PocketPC
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,18 +34,30 @@ using System.Globalization;
namespace Newtonsoft.Json.Serialization
{
/// <summary>
/// Get and set values for a <see cref="MemberInfo"/> using dynamic methods.
/// </summary>
public class DynamicValueProvider : IValueProvider
{
private readonly MemberInfo _memberInfo;
private Func<object, object> _getter;
private Action<object, object> _setter;
/// <summary>
/// Initializes a new instance of the <see cref="DynamicValueProvider"/> class.
/// </summary>
/// <param name="memberInfo">The member info.</param>
public DynamicValueProvider(MemberInfo memberInfo)
{
ValidationUtils.ArgumentNotNull(memberInfo, "memberInfo");
_memberInfo = memberInfo;
}
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="target">The target to set the value on.</param>
/// <param name="value">The value to set on the target.</param>
public void SetValue(object target, object value)
{
try
@@ -36,6 +73,11 @@ namespace Newtonsoft.Json.Serialization
}
}
/// <summary>
/// Gets the value.
/// </summary>
/// <param name="target">The target to get the value from.</param>
/// <returns>The value.</returns>
public object GetValue(object target)
{
try
@@ -1,13 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#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
namespace Newtonsoft.Json.Serialization
{
/// <summary>
/// Provides methods to get and set values.
/// </summary>
public interface IValueProvider
{
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="target">The target to set the value on.</param>
/// <param name="value">The value to set on the target.</param>
void SetValue(object target, object value);
/// <summary>
/// Gets the value.
/// </summary>
/// <param name="target">The target to get the value from.</param>
/// <returns>The value.</returns>
object GetValue(object target);
}
}
@@ -79,7 +79,16 @@ namespace Newtonsoft.Json.Serialization
public MethodInfo OnSerializing { get; set; }
#endif
/// <summary>
/// Gets or sets the default creator.
/// </summary>
/// <value>The default creator.</value>
public Func<object> DefaultCreator { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [default creator non public].
/// </summary>
/// <value><c>true</c> if the default object creator is non-public; otherwise, <c>false</c>.</value>
public bool DefaultCreatorNonPublic { get; set; }
/// <summary>
@@ -23,7 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System.Reflection;
using System;
namespace Newtonsoft.Json.Serialization
@@ -45,8 +44,16 @@ namespace Newtonsoft.Json.Serialization
/// <value>The <see cref="IValueProvider"/> that will get and set the <see cref="JsonProperty"/> during serialization.</value>
public IValueProvider ValueProvider { get; set; }
/// <summary>
/// Gets or sets the type of the property.
/// </summary>
/// <value>The type of the property.</value>
public Type PropertyType { get; set; }
/// <summary>
/// Gets or sets the converter.
/// </summary>
/// <value>The converter.</value>
public JsonConverter Converter { get; set; }
/// <summary>
@@ -39,6 +39,10 @@ namespace Newtonsoft.Json.Serialization
{
private readonly JsonObjectContract _contract;
/// <summary>
/// Initializes a new instance of the <see cref="JsonPropertyCollection"/> class.
/// </summary>
/// <param name="contract">The contract.</param>
public JsonPropertyCollection(JsonObjectContract contract)
{
ValidationUtils.ArgumentNotNull(contract, "contract");
@@ -1,4 +1,29 @@
using System;
#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.Text;
@@ -8,16 +33,28 @@ using System.Globalization;
namespace Newtonsoft.Json.Serialization
{
/// <summary>
/// Get and set values for a <see cref="MemberInfo"/> using reflection.
/// </summary>
public class ReflectionValueProvider : IValueProvider
{
private readonly MemberInfo _memberInfo;
/// <summary>
/// Initializes a new instance of the <see cref="ReflectionValueProvider"/> class.
/// </summary>
/// <param name="memberInfo">The member info.</param>
public ReflectionValueProvider(MemberInfo memberInfo)
{
ValidationUtils.ArgumentNotNull(memberInfo, "memberInfo");
_memberInfo = memberInfo;
}
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="target">The target to set the value on.</param>
/// <param name="value">The value to set on the target.</param>
public void SetValue(object target, object value)
{
try
@@ -30,6 +67,11 @@ namespace Newtonsoft.Json.Serialization
}
}
/// <summary>
/// Gets the value.
/// </summary>
/// <param name="target">The target to get the value from.</param>
/// <returns>The value.</returns>
public object GetValue(object target)
{
try
@@ -12,12 +12,12 @@ using System.Globalization;
namespace Newtonsoft.Json.Utilities
{
public class DynamicWrapperBase
internal class DynamicWrapperBase
{
internal protected object UnderlyingObject;
}
public static class DynamicWrapper
internal static class DynamicWrapper
{
private static readonly object _lock = new object();
private static readonly WrapperDictionary _wrapperDictionary = new WrapperDictionary();
@@ -224,7 +224,7 @@ namespace Newtonsoft.Json.Utilities
}
}
public static class TypeExtensions
internal static class TypeExtensions
{
public static MethodInfo GetGenericMethod(this Type type, string name, params Type[] parameterTypes)
{