-Updated source code to VS2010

-Updated main project to .NET 4.0
-Updated to psake 4.0
-Changed assembly version to 4.0.0.0
-Added ICustomTypeDescriptor implementation to JObject, removed JTypeDescriptionProvider and JTypeDescriptor
-Changed serialization of collections to use iterator rather than indexer
-Removed Compact Framework project
-Fixed XML documentation warnings
This commit is contained in:
JamesNK
2010-08-31 02:19:41 +00:00
parent 97d9cf82ef
commit 12a91cce9e
37 changed files with 1686 additions and 1932 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json
}
/// <summary>
/// Gets or sets how many IndentChars to write for each level in the hierarchy when <paramref name="Formatting"/> is set to <c>Formatting.Indented</c>.
/// Gets or sets how many IndentChars to write for each level in the hierarchy when <see cref="Formatting"/> is set to <c>Formatting.Indented</c>.
/// </summary>
public int Indentation
{
@@ -86,7 +86,7 @@ namespace Newtonsoft.Json
}
/// <summary>
/// Gets or sets which character to use for indenting when <paramref name="Formatting"/> is set to <c>Formatting.Indented</c>.
/// Gets or sets which character to use for indenting when <see cref="Formatting"/> is set to <c>Formatting.Indented</c>.
/// </summary>
public char IndentChar
{
@@ -80,8 +80,6 @@ namespace Newtonsoft.Json.Linq.ComponentModel
public override object GetValue(object component)
{
JToken token = CastInstance(component)[Name];
//if (token is JValue)
// return ((JValue) token).Value;
return token;
}
@@ -1,47 +0,0 @@
#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 && !SILVERLIGHT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Linq.ComponentModel
{
internal class JTypeDescriptionProvider : TypeDescriptionProvider
{
public override ICustomTypeDescriptor GetTypeDescriptor(Type type, object instance)
{
JObject o = instance as JObject;
if (o != null)
return new JTypeDescriptor(o);
return base.GetTypeDescriptor(type, instance);
}
}
}
#endif
@@ -1,209 +0,0 @@
#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 !SILVERLIGHT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Linq.ComponentModel
{
/// <summary>
/// Represents a view of a <see cref="JObject"/>.
/// </summary>
public class JTypeDescriptor : ICustomTypeDescriptor
{
private readonly JObject _value;
/// <summary>
/// Initializes a new instance of the <see cref="JTypeDescriptor"/> class.
/// </summary>
/// <param name="value">The value.</param>
public JTypeDescriptor(JObject value)
{
ValidationUtils.ArgumentNotNull(value, "value");
_value = value;
}
/// <summary>
/// Returns the properties for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> that represents the properties for this component instance.
/// </returns>
public virtual PropertyDescriptorCollection GetProperties()
{
return GetProperties(null);
}
private static Type GetTokenPropertyType(JToken token)
{
if (token is JValue)
{
JValue v = (JValue) token;
return (v.Value != null) ? v.Value.GetType() : typeof (object);
}
return token.GetType();
}
/// <summary>
/// Returns the properties for this instance of a component using the attribute array as a filter.
/// </summary>
/// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> that represents the filtered properties for this component instance.
/// </returns>
public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection descriptors = new PropertyDescriptorCollection(null);
if (_value != null)
{
foreach (KeyValuePair<string, JToken> propertyValue in _value)
{
descriptors.Add(new JPropertyDescriptor(propertyValue.Key, GetTokenPropertyType(propertyValue.Value)));
}
}
return descriptors;
}
/// <summary>
/// Returns a collection of custom attributes for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.AttributeCollection"/> containing the attributes for this object.
/// </returns>
public AttributeCollection GetAttributes()
{
return AttributeCollection.Empty;
}
/// <summary>
/// Returns the class name of this instance of a component.
/// </summary>
/// <returns>
/// The class name of the object, or null if the class does not have a name.
/// </returns>
public string GetClassName()
{
return null;
}
/// <summary>
/// Returns the name of this instance of a component.
/// </summary>
/// <returns>
/// The name of the object, or null if the object does not have a name.
/// </returns>
public string GetComponentName()
{
return null;
}
/// <summary>
/// Returns a type converter for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.TypeConverter"/> that is the converter for this object, or null if there is no <see cref="T:System.ComponentModel.TypeConverter"/> for this object.
/// </returns>
public TypeConverter GetConverter()
{
return new TypeConverter();
}
/// <summary>
/// Returns the default event for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptor"/> that represents the default event for this object, or null if this object does not have events.
/// </returns>
public EventDescriptor GetDefaultEvent()
{
return null;
}
/// <summary>
/// Returns the default property for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptor"/> that represents the default property for this object, or null if this object does not have properties.
/// </returns>
public PropertyDescriptor GetDefaultProperty()
{
return null;
}
/// <summary>
/// Returns an editor of the specified type for this instance of a component.
/// </summary>
/// <param name="editorBaseType">A <see cref="T:System.Type"/> that represents the editor for this object.</param>
/// <returns>
/// An <see cref="T:System.Object"/> of the specified type that is the editor for this object, or null if the editor cannot be found.
/// </returns>
public object GetEditor(Type editorBaseType)
{
return null;
}
/// <summary>
/// Returns the events for this instance of a component using the specified attribute array as a filter.
/// </summary>
/// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptorCollection"/> that represents the filtered events for this component instance.
/// </returns>
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return EventDescriptorCollection.Empty;
}
/// <summary>
/// Returns the events for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptorCollection"/> that represents the events for this component instance.
/// </returns>
public EventDescriptorCollection GetEvents()
{
return EventDescriptorCollection.Empty;
}
/// <summary>
/// Returns an object that contains the property described by the specified property descriptor.
/// </summary>
/// <param name="pd">A <see cref="T:System.ComponentModel.PropertyDescriptor"/> that represents the property whose owner is to be found.</param>
/// <returns>
/// An <see cref="T:System.Object"/> that represents the owner of the specified property.
/// </returns>
public object GetPropertyOwner(PropertyDescriptor pd)
{
return null;
}
}
}
#endif
+3 -7
View File
@@ -779,13 +779,9 @@ namespace Newtonsoft.Json.Linq
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
JObject o = First as JObject;
if (o != null)
{
// explicitly use constructor because compact framework has no provider
JTypeDescriptor descriptor = new JTypeDescriptor(o);
return descriptor.GetProperties();
}
ICustomTypeDescriptor d = First as ICustomTypeDescriptor;
if (d != null)
return d.GetProperties();
return null;
}
+162 -3
View File
@@ -40,10 +40,10 @@ namespace Newtonsoft.Json.Linq
/// <summary>
/// Represents a JSON object.
/// </summary>
#if !PocketPC && !SILVERLIGHT
[TypeDescriptionProvider(typeof(JTypeDescriptionProvider))]
#endif
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
#if !PocketPC && !SILVERLIGHT
, ICustomTypeDescriptor
#endif
#if !PocketPC && !SILVERLIGHT && !NET20
, INotifyPropertyChanging
#endif
@@ -491,5 +491,164 @@ namespace Newtonsoft.Json.Linq
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
#endif
#if !PocketPC && !SILVERLIGHT
// include custom type descriptor on JObject rather than use a provider because the properties are specific to a type
#region ICustomTypeDescriptor
/// <summary>
/// Returns the properties for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> that represents the properties for this component instance.
/// </returns>
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor) this).GetProperties(null);
}
private static Type GetTokenPropertyType(JToken token)
{
if (token is JValue)
{
JValue v = (JValue)token;
return (v.Value != null) ? v.Value.GetType() : typeof(object);
}
return token.GetType();
}
/// <summary>
/// Returns the properties for this instance of a component using the attribute array as a filter.
/// </summary>
/// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> that represents the filtered properties for this component instance.
/// </returns>
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection descriptors = new PropertyDescriptorCollection(null);
foreach (KeyValuePair<string, JToken> propertyValue in this)
{
descriptors.Add(new JPropertyDescriptor(propertyValue.Key, GetTokenPropertyType(propertyValue.Value)));
}
return descriptors;
}
/// <summary>
/// Returns a collection of custom attributes for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.AttributeCollection"/> containing the attributes for this object.
/// </returns>
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return AttributeCollection.Empty;
}
/// <summary>
/// Returns the class name of this instance of a component.
/// </summary>
/// <returns>
/// The class name of the object, or null if the class does not have a name.
/// </returns>
string ICustomTypeDescriptor.GetClassName()
{
return null;
}
/// <summary>
/// Returns the name of this instance of a component.
/// </summary>
/// <returns>
/// The name of the object, or null if the object does not have a name.
/// </returns>
string ICustomTypeDescriptor.GetComponentName()
{
return null;
}
/// <summary>
/// Returns a type converter for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.TypeConverter"/> that is the converter for this object, or null if there is no <see cref="T:System.ComponentModel.TypeConverter"/> for this object.
/// </returns>
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return new TypeConverter();
}
/// <summary>
/// Returns the default event for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptor"/> that represents the default event for this object, or null if this object does not have events.
/// </returns>
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return null;
}
/// <summary>
/// Returns the default property for this instance of a component.
/// </summary>
/// <returns>
/// A <see cref="T:System.ComponentModel.PropertyDescriptor"/> that represents the default property for this object, or null if this object does not have properties.
/// </returns>
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return null;
}
/// <summary>
/// Returns an editor of the specified type for this instance of a component.
/// </summary>
/// <param name="editorBaseType">A <see cref="T:System.Type"/> that represents the editor for this object.</param>
/// <returns>
/// An <see cref="T:System.Object"/> of the specified type that is the editor for this object, or null if the editor cannot be found.
/// </returns>
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return null;
}
/// <summary>
/// Returns the events for this instance of a component using the specified attribute array as a filter.
/// </summary>
/// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptorCollection"/> that represents the filtered events for this component instance.
/// </returns>
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return EventDescriptorCollection.Empty;
}
/// <summary>
/// Returns the events for this instance of a component.
/// </summary>
/// <returns>
/// An <see cref="T:System.ComponentModel.EventDescriptorCollection"/> that represents the events for this component instance.
/// </returns>
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return EventDescriptorCollection.Empty;
}
/// <summary>
/// Returns an object that contains the property described by the specified property descriptor.
/// </summary>
/// <param name="pd">A <see cref="T:System.ComponentModel.PropertyDescriptor"/> that represents the property whose owner is to be found.</param>
/// <returns>
/// An <see cref="T:System.Object"/> that represents the owner of the specified property.
/// </returns>
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
return null;
}
#endregion
#endif
}
}
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Linq
/// <summary>
/// Determines whether the specified objects are equal.
/// </summary>
/// <param name="x">The first object of type <paramref name="T"/> to compare.</param>
/// <param name="y">The second object of type <paramref name="T"/> to compare.</param>
/// <param name="x">The first object of type <see cref="JToken"/> to compare.</param>
/// <param name="y">The second object of type <see cref="JToken"/> to compare.</param>
/// <returns>
/// true if the specified objects are equal; otherwise, false.
/// </returns>
@@ -1,223 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{256AA604-F61B-4B6D-8D51-C8E6AB11E435}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json</RootNamespace>
<AssemblyName>Newtonsoft.Json.Compact</AssemblyName>
<ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PlatformFamilyName>PocketPC</PlatformFamilyName>
<PlatformID>b2c48bd2-963d-4549-9169-1fa021dce484</PlatformID>
<OSVersion>5.2</OSVersion>
<DeployDirSuffix>Newtonsoft.Json.Compact</DeployDirSuffix>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<NativePlatformName>Windows Mobile 6 Professional SDK</NativePlatformName>
<FormFactorID>
</FormFactorID>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\Compact\</OutputPath>
<DefineConstants>DEBUG;TRACE;$(PlatformFamilyName)</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<FileAlignment>512</FileAlignment>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\Compact\</OutputPath>
<DefineConstants>TRACE;$(PlatformFamilyName)</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<FileAlignment>512</FileAlignment>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DocumentationFile>bin\Release\Compact\Newtonsoft.Json.Compact.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bson\BsonBinaryType.cs" />
<Compile Include="Bson\BsonBinaryWriter.cs" />
<Compile Include="Bson\BsonObjectId.cs" />
<Compile Include="Bson\BsonReader.cs" />
<Compile Include="Bson\BsonToken.cs" />
<Compile Include="Bson\BsonType.cs" />
<Compile Include="Bson\BsonWriter.cs" />
<Compile Include="ConstructorHandling.cs" />
<Compile Include="Converters\BinaryConverter.cs" />
<Compile Include="Converters\BsonObjectIdConverter.cs" />
<Compile Include="Converters\CustomCreationConverter.cs" />
<Compile Include="Converters\DataSetConverter.cs" />
<Compile Include="Converters\DataTableConverter.cs" />
<Compile Include="Converters\DateTimeConverterBase.cs" />
<Compile Include="Converters\EntityKeyMemberConverter.cs" />
<Compile Include="Converters\KeyValuePairConverter.cs" />
<Compile Include="Converters\RegexConverter.cs" />
<Compile Include="Converters\StringEnumConverter.cs" />
<Compile Include="FormatterAssemblyStyle.cs" />
<Compile Include="IJsonLineInfo.cs" />
<Compile Include="JsonArrayAttribute.cs" />
<Compile Include="JsonContainerAttribute.cs" />
<Compile Include="DefaultValueHandling.cs" />
<Compile Include="JsonConverterAttribute.cs" />
<Compile Include="JsonObjectAttribute.cs" />
<Compile Include="JsonSerializerSettings.cs" />
<Compile Include="JsonValidatingReader.cs" />
<Compile Include="Linq\ComponentModel\JPropertyDescriptor.cs" />
<Compile Include="Linq\ComponentModel\JTypeDescriptionProvider.cs" />
<Compile Include="Linq\ComponentModel\JTypeDescriptor.cs" />
<Compile Include="Linq\IJEnumerable.cs" />
<Compile Include="Linq\JPath.cs" />
<Compile Include="Linq\JRaw.cs" />
<Compile Include="Linq\JTokenEqualityComparer.cs" />
<Compile Include="Linq\JTokenReader.cs" />
<Compile Include="Linq\JTokenType.cs" />
<Compile Include="Linq\JTokenWriter.cs" />
<Compile Include="MemberSerialization.cs" />
<Compile Include="ObjectCreationHandling.cs" />
<Compile Include="Converters\IsoDateTimeConverter.cs" />
<Compile Include="Converters\JavaScriptDateTimeConverter.cs" />
<Compile Include="Converters\JsonDateTimeSerializationMode.cs" />
<Compile Include="Converters\XmlNodeConverter.cs" />
<Compile Include="JsonTextReader.cs" />
<Compile Include="JsonPropertyAttribute.cs" />
<Compile Include="JsonIgnoreAttribute.cs" />
<Compile Include="JsonTextWriter.cs" />
<Compile Include="JsonWriterException.cs" />
<Compile Include="JsonReaderException.cs" />
<Compile Include="JsonConverter.cs" />
<Compile Include="JsonConverterCollection.cs" />
<Compile Include="JsonReader.cs" />
<Compile Include="JsonConvert.cs" />
<Compile Include="JsonSerializationException.cs" />
<Compile Include="JsonSerializer.cs" />
<Compile Include="Linq\Extensions.cs" />
<Compile Include="Linq\JConstructor.cs" />
<Compile Include="Linq\JContainer.cs" />
<Compile Include="Linq\JEnumerable.cs" />
<Compile Include="Linq\JObject.cs" />
<Compile Include="Linq\JArray.cs" />
<Compile Include="Linq\JToken.cs" />
<Compile Include="Linq\JProperty.cs" />
<Compile Include="Linq\JValue.cs" />
<Compile Include="PreserveReferencesHandling.cs" />
<Compile Include="Required.cs" />
<Compile Include="Schema\Extensions.cs" />
<Compile Include="Schema\JsonSchemaException.cs" />
<Compile Include="Schema\JsonSchemaModel.cs" />
<Compile Include="Schema\JsonSchemaModelBuilder.cs" />
<Compile Include="Schema\JsonSchemaNodeCollection.cs" />
<Compile Include="Schema\JsonSchemaNode.cs" />
<Compile Include="Schema\JsonSchemaWriter.cs" />
<Compile Include="Schema\UndefinedSchemaIdHandling.cs" />
<Compile Include="Schema\ValidationEventArgs.cs" />
<Compile Include="Schema\ValidationEventHandler.cs" />
<Compile Include="SerializationBinder.cs" />
<Compile Include="Serialization\CachedAttributeGetter.cs" />
<Compile Include="Serialization\CamelCasePropertyNamesContractResolver.cs" />
<Compile Include="Serialization\DefaultContractResolver.cs" />
<Compile Include="Serialization\DefaultReferenceResolver.cs" />
<Compile Include="Serialization\DefaultSerializationBinder.cs" />
<Compile Include="Serialization\DynamicValueProvider.cs" />
<Compile Include="Serialization\ErrorContext.cs" />
<Compile Include="Serialization\ErrorEventArgs.cs" />
<Compile Include="Serialization\IContractResolver.cs" />
<Compile Include="Serialization\IReferenceResolver.cs" />
<Compile Include="Serialization\IValueProvider.cs" />
<Compile Include="Serialization\JsonArrayContract.cs" />
<Compile Include="Serialization\JsonContract.cs" />
<Compile Include="Serialization\JsonDictionaryContract.cs" />
<Compile Include="MissingMemberHandling.cs" />
<Compile Include="NullValueHandling.cs" />
<Compile Include="ReferenceLoopHandling.cs" />
<Compile Include="Schema\JsonSchema.cs" />
<Compile Include="Schema\JsonSchemaBuilder.cs" />
<Compile Include="Schema\JsonSchemaConstants.cs" />
<Compile Include="Schema\JsonSchemaGenerator.cs" />
<Compile Include="Schema\JsonSchemaResolver.cs" />
<Compile Include="Schema\JsonSchemaType.cs" />
<Compile Include="Serialization\JsonFormatterConverter.cs" />
<Compile Include="Serialization\JsonISerializableContract.cs" />
<Compile Include="Serialization\JsonLinqContract.cs" />
<Compile Include="Serialization\JsonObjectContract.cs" />
<Compile Include="Serialization\JsonPrimitiveContract.cs" />
<Compile Include="Serialization\JsonProperty.cs" />
<Compile Include="Serialization\JsonPropertyCollection.cs" />
<Compile Include="Serialization\JsonSerializerInternalBase.cs" />
<Compile Include="Serialization\JsonSerializerInternalReader.cs" />
<Compile Include="Serialization\JsonSerializerInternalWriter.cs" />
<Compile Include="Serialization\JsonSerializerProxy.cs" />
<Compile Include="Serialization\JsonStringContract.cs" />
<Compile Include="Serialization\JsonTypeReflector.cs" />
<Compile Include="Serialization\LateBoundMetadataTypeAttribute.cs" />
<Compile Include="Serialization\ObjectConstructor.cs" />
<Compile Include="Serialization\OnErrorAttribute.cs" />
<Compile Include="Serialization\ReflectionValueProvider.cs" />
<Compile Include="StreamingContext.cs" />
<Compile Include="TypeNameHandling.cs" />
<Compile Include="Utilities\Base64Encoder.cs" />
<Compile Include="Utilities\BidirectionalDictionary.cs" />
<Compile Include="Utilities\ConvertUtils.cs" />
<Compile Include="Utilities\CollectionWrapper.cs" />
<Compile Include="Utilities\DateTimeUtils.cs" />
<Compile Include="Utilities\DictionaryWrapper.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactory.cs" />
<Compile Include="Utilities\DynamicWrapper.cs" />
<Compile Include="Utilities\EnumUtils.cs" />
<Compile Include="Utilities\EnumValue.cs" />
<Compile Include="Utilities\EnumValues.cs" />
<Compile Include="Utilities\ILGeneratorExtensions.cs" />
<Compile Include="Utilities\JavaScriptUtils.cs" />
<Compile Include="JsonToken.cs" />
<Compile Include="JsonWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\CollectionUtils.cs" />
<Compile Include="Utilities\LateBoundReflectionDelegateFactory.cs" />
<Compile Include="Utilities\ListWrapper.cs" />
<Compile Include="Utilities\MathUtils.cs" />
<Compile Include="Utilities\MethodCall.cs" />
<Compile Include="Utilities\MiscellaneousUtils.cs" />
<Compile Include="Utilities\ReflectionDelegateFactory.cs" />
<Compile Include="Utilities\ReflectionUtils.cs" />
<Compile Include="Utilities\StringBuffer.cs" />
<Compile Include="Utilities\StringUtils.cs" />
<Compile Include="Utilities\ThreadSafeStore.cs" />
<Compile Include="Utilities\ValidationUtils.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
<HostingProcess disable="1" />
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
File diff suppressed because one or more lines are too long
@@ -1,4 +1,8 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,7 +14,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json</RootNamespace>
<AssemblyName>Newtonsoft.Json.Silverlight</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>false</ThrowErrorsInValidation>
@@ -19,6 +23,25 @@
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -31,6 +54,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>Bin\Debug\Silverlight\Newtonsoft.Json.Silverlight.xml</DocumentationFile>
<CodeAnalysisRuleSet>Newtonsoft.Json.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -42,6 +67,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>Bin\Release\Silverlight\Newtonsoft.Json.Silverlight.xml</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.Serialization" />
@@ -100,8 +126,6 @@
<Compile Include="JsonWriter.cs" />
<Compile Include="JsonWriterException.cs" />
<Compile Include="Linq\ComponentModel\JPropertyDescriptor.cs" />
<Compile Include="Linq\ComponentModel\JTypeDescriptionProvider.cs" />
<Compile Include="Linq\ComponentModel\JTypeDescriptor.cs" />
<Compile Include="Linq\Extensions.cs" />
<Compile Include="Linq\IJEnumerable.cs" />
<Compile Include="Linq\JArray.cs" />
@@ -202,7 +226,24 @@
<Compile Include="Schema\JsonSchemaType.cs" />
<Compile Include="Serialization\JsonTypeReflector.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" Condition="" />
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
File diff suppressed because one or more lines are too long
+234
View File
@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Newtonsoft.Json.ruleset" ToolsVersion="10.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="None" />
<Rule Id="CA1001" Action="None" />
<Rule Id="CA1002" Action="None" />
<Rule Id="CA1003" Action="None" />
<Rule Id="CA1004" Action="None" />
<Rule Id="CA1005" Action="None" />
<Rule Id="CA1006" Action="None" />
<Rule Id="CA1007" Action="None" />
<Rule Id="CA1008" Action="None" />
<Rule Id="CA1009" Action="None" />
<Rule Id="CA1010" Action="None" />
<Rule Id="CA1011" Action="None" />
<Rule Id="CA1012" Action="None" />
<Rule Id="CA1013" Action="None" />
<Rule Id="CA1014" Action="None" />
<Rule Id="CA1016" Action="None" />
<Rule Id="CA1017" Action="None" />
<Rule Id="CA1018" Action="None" />
<Rule Id="CA1019" Action="None" />
<Rule Id="CA1020" Action="None" />
<Rule Id="CA1021" Action="None" />
<Rule Id="CA1023" Action="None" />
<Rule Id="CA1024" Action="None" />
<Rule Id="CA1025" Action="None" />
<Rule Id="CA1026" Action="None" />
<Rule Id="CA1027" Action="None" />
<Rule Id="CA1028" Action="None" />
<Rule Id="CA1030" Action="None" />
<Rule Id="CA1031" Action="None" />
<Rule Id="CA1032" Action="None" />
<Rule Id="CA1033" Action="None" />
<Rule Id="CA1034" Action="None" />
<Rule Id="CA1035" Action="None" />
<Rule Id="CA1036" Action="None" />
<Rule Id="CA1038" Action="None" />
<Rule Id="CA1039" Action="None" />
<Rule Id="CA1040" Action="None" />
<Rule Id="CA1041" Action="None" />
<Rule Id="CA1043" Action="None" />
<Rule Id="CA1044" Action="None" />
<Rule Id="CA1045" Action="None" />
<Rule Id="CA1046" Action="None" />
<Rule Id="CA1047" Action="None" />
<Rule Id="CA1048" Action="None" />
<Rule Id="CA1049" Action="None" />
<Rule Id="CA1050" Action="None" />
<Rule Id="CA1051" Action="None" />
<Rule Id="CA1052" Action="None" />
<Rule Id="CA1053" Action="None" />
<Rule Id="CA1054" Action="None" />
<Rule Id="CA1055" Action="None" />
<Rule Id="CA1056" Action="None" />
<Rule Id="CA1057" Action="None" />
<Rule Id="CA1058" Action="None" />
<Rule Id="CA1059" Action="None" />
<Rule Id="CA1060" Action="None" />
<Rule Id="CA1061" Action="None" />
<Rule Id="CA1062" Action="None" />
<Rule Id="CA1063" Action="None" />
<Rule Id="CA1064" Action="None" />
<Rule Id="CA1065" Action="None" />
<Rule Id="CA1300" Action="None" />
<Rule Id="CA1301" Action="None" />
<Rule Id="CA1302" Action="None" />
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1306" Action="None" />
<Rule Id="CA1307" Action="None" />
<Rule Id="CA1308" Action="None" />
<Rule Id="CA1309" Action="None" />
<Rule Id="CA1400" Action="None" />
<Rule Id="CA1401" Action="None" />
<Rule Id="CA1402" Action="None" />
<Rule Id="CA1403" Action="None" />
<Rule Id="CA1404" Action="None" />
<Rule Id="CA1405" Action="None" />
<Rule Id="CA1406" Action="None" />
<Rule Id="CA1407" Action="None" />
<Rule Id="CA1408" Action="None" />
<Rule Id="CA1409" Action="None" />
<Rule Id="CA1410" Action="None" />
<Rule Id="CA1411" Action="None" />
<Rule Id="CA1412" Action="None" />
<Rule Id="CA1413" Action="None" />
<Rule Id="CA1414" Action="None" />
<Rule Id="CA1415" Action="None" />
<Rule Id="CA1500" Action="None" />
<Rule Id="CA1501" Action="None" />
<Rule Id="CA1502" Action="None" />
<Rule Id="CA1504" Action="None" />
<Rule Id="CA1505" Action="None" />
<Rule Id="CA1506" Action="None" />
<Rule Id="CA1600" Action="None" />
<Rule Id="CA1601" Action="None" />
<Rule Id="CA1700" Action="None" />
<Rule Id="CA1701" Action="None" />
<Rule Id="CA1702" Action="None" />
<Rule Id="CA1703" Action="None" />
<Rule Id="CA1704" Action="None" />
<Rule Id="CA1707" Action="None" />
<Rule Id="CA1708" Action="None" />
<Rule Id="CA1709" Action="None" />
<Rule Id="CA1710" Action="None" />
<Rule Id="CA1711" Action="None" />
<Rule Id="CA1712" Action="None" />
<Rule Id="CA1713" Action="None" />
<Rule Id="CA1714" Action="None" />
<Rule Id="CA1715" Action="None" />
<Rule Id="CA1716" Action="None" />
<Rule Id="CA1717" Action="None" />
<Rule Id="CA1719" Action="None" />
<Rule Id="CA1720" Action="None" />
<Rule Id="CA1721" Action="None" />
<Rule Id="CA1722" Action="None" />
<Rule Id="CA1724" Action="None" />
<Rule Id="CA1725" Action="None" />
<Rule Id="CA1726" Action="None" />
<Rule Id="CA1800" Action="None" />
<Rule Id="CA1801" Action="None" />
<Rule Id="CA1802" Action="None" />
<Rule Id="CA1804" Action="None" />
<Rule Id="CA1806" Action="None" />
<Rule Id="CA1809" Action="None" />
<Rule Id="CA1810" Action="None" />
<Rule Id="CA1811" Action="None" />
<Rule Id="CA1812" Action="None" />
<Rule Id="CA1813" Action="None" />
<Rule Id="CA1814" Action="None" />
<Rule Id="CA1815" Action="None" />
<Rule Id="CA1816" Action="None" />
<Rule Id="CA1819" Action="None" />
<Rule Id="CA1820" Action="None" />
<Rule Id="CA1821" Action="None" />
<Rule Id="CA1822" Action="None" />
<Rule Id="CA1823" Action="None" />
<Rule Id="CA1824" Action="None" />
<Rule Id="CA1900" Action="None" />
<Rule Id="CA1901" Action="None" />
<Rule Id="CA1903" Action="Error" />
<Rule Id="CA2000" Action="None" />
<Rule Id="CA2001" Action="None" />
<Rule Id="CA2002" Action="None" />
<Rule Id="CA2003" Action="None" />
<Rule Id="CA2004" Action="None" />
<Rule Id="CA2006" Action="None" />
<Rule Id="CA2100" Action="None" />
<Rule Id="CA2101" Action="None" />
<Rule Id="CA2102" Action="None" />
<Rule Id="CA2103" Action="None" />
<Rule Id="CA2104" Action="None" />
<Rule Id="CA2105" Action="None" />
<Rule Id="CA2106" Action="None" />
<Rule Id="CA2107" Action="None" />
<Rule Id="CA2108" Action="None" />
<Rule Id="CA2109" Action="None" />
<Rule Id="CA2111" Action="None" />
<Rule Id="CA2112" Action="None" />
<Rule Id="CA2114" Action="None" />
<Rule Id="CA2115" Action="None" />
<Rule Id="CA2116" Action="None" />
<Rule Id="CA2117" Action="None" />
<Rule Id="CA2118" Action="None" />
<Rule Id="CA2119" Action="None" />
<Rule Id="CA2120" Action="None" />
<Rule Id="CA2121" Action="None" />
<Rule Id="CA2122" Action="None" />
<Rule Id="CA2123" Action="None" />
<Rule Id="CA2124" Action="None" />
<Rule Id="CA2126" Action="None" />
<Rule Id="CA2130" Action="None" />
<Rule Id="CA2131" Action="None" />
<Rule Id="CA2132" Action="None" />
<Rule Id="CA2133" Action="None" />
<Rule Id="CA2134" Action="None" />
<Rule Id="CA2135" Action="None" />
<Rule Id="CA2136" Action="None" />
<Rule Id="CA2137" Action="None" />
<Rule Id="CA2138" Action="None" />
<Rule Id="CA2139" Action="None" />
<Rule Id="CA2140" Action="None" />
<Rule Id="CA2141" Action="None" />
<Rule Id="CA2142" Action="None" />
<Rule Id="CA2143" Action="None" />
<Rule Id="CA2144" Action="None" />
<Rule Id="CA2145" Action="None" />
<Rule Id="CA2146" Action="None" />
<Rule Id="CA2147" Action="None" />
<Rule Id="CA2149" Action="None" />
<Rule Id="CA2200" Action="None" />
<Rule Id="CA2201" Action="None" />
<Rule Id="CA2202" Action="None" />
<Rule Id="CA2204" Action="None" />
<Rule Id="CA2205" Action="None" />
<Rule Id="CA2207" Action="None" />
<Rule Id="CA2208" Action="None" />
<Rule Id="CA2210" Action="None" />
<Rule Id="CA2211" Action="None" />
<Rule Id="CA2212" Action="None" />
<Rule Id="CA2213" Action="None" />
<Rule Id="CA2214" Action="None" />
<Rule Id="CA2215" Action="None" />
<Rule Id="CA2216" Action="None" />
<Rule Id="CA2217" Action="None" />
<Rule Id="CA2218" Action="None" />
<Rule Id="CA2219" Action="None" />
<Rule Id="CA2220" Action="None" />
<Rule Id="CA2221" Action="None" />
<Rule Id="CA2222" Action="None" />
<Rule Id="CA2223" Action="None" />
<Rule Id="CA2224" Action="None" />
<Rule Id="CA2225" Action="None" />
<Rule Id="CA2226" Action="None" />
<Rule Id="CA2227" Action="None" />
<Rule Id="CA2228" Action="None" />
<Rule Id="CA2229" Action="None" />
<Rule Id="CA2230" Action="None" />
<Rule Id="CA2231" Action="None" />
<Rule Id="CA2232" Action="None" />
<Rule Id="CA2233" Action="None" />
<Rule Id="CA2234" Action="None" />
<Rule Id="CA2235" Action="None" />
<Rule Id="CA2236" Action="None" />
<Rule Id="CA2237" Action="None" />
<Rule Id="CA2238" Action="None" />
<Rule Id="CA2239" Action="None" />
<Rule Id="CA2240" Action="None" />
<Rule Id="CA2241" Action="None" />
<Rule Id="CA2242" Action="None" />
<Rule Id="CA2243" Action="None" />
</Rules>
</RuleSet>
@@ -95,9 +95,9 @@ using System.Security;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.5.0.0")]
[assembly: AssemblyVersion("4.0.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("3.5.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
#endif
[assembly: CLSCompliant(true)]
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json.Utilities;
using System.Collections;
@@ -74,15 +75,22 @@ namespace Newtonsoft.Json.Serialization
|| UnderlyingType.IsArray)
return new CollectionWrapper<object>((IList)list);
if (_genericWrapperType == null)
if (_genericCollectionDefinitionType != null)
{
_genericWrapperType = ReflectionUtils.MakeGenericType(typeof(CollectionWrapper<>), CollectionItemType);
if (_genericWrapperType == null)
{
_genericWrapperType = ReflectionUtils.MakeGenericType(typeof (CollectionWrapper<>), CollectionItemType);
ConstructorInfo genericWrapperConstructor = _genericWrapperType.GetConstructor(new[] { _genericCollectionDefinitionType });
_genericWrapperCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(genericWrapperConstructor);
ConstructorInfo genericWrapperConstructor = _genericWrapperType.GetConstructor(new[] {_genericCollectionDefinitionType});
_genericWrapperCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(genericWrapperConstructor);
}
return (IWrappedCollection) _genericWrapperCreator(null, list);
}
else
{
return new CollectionWrapper<object>((IList<object>)((IEnumerable)list).Cast<object>().ToList());
}
return (IWrappedCollection)_genericWrapperCreator(null, list);
}
private bool IsTypeGenericCollectionInterface(Type type)
@@ -34,6 +34,7 @@ using System.Runtime.Serialization.Formatters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
using System.Runtime.Serialization;
using System.Security;
namespace Newtonsoft.Json.Serialization
{
@@ -118,20 +119,8 @@ namespace Newtonsoft.Json.Serialization
}
else if (valueContract is JsonArrayContract)
{
if (value is IList)
{
SerializeList(writer, (IList)value, (JsonArrayContract)valueContract, member, collectionValueContract);
}
else if (value is IEnumerable)
{
SerializeList(writer, ((IEnumerable)value).Cast<object>().ToList(), (JsonArrayContract)valueContract, member, collectionValueContract);
}
else
{
throw new Exception(
"Cannot serialize '{0}' into a JSON array. Type does not implement IEnumerable.".FormatWith(
CultureInfo.InvariantCulture, value.GetType()));
}
JsonArrayContract arrayContract = (JsonArrayContract) valueContract;
SerializeList(writer, arrayContract.CreateWrapper(value), arrayContract, member, collectionValueContract);
}
else if (valueContract is JsonLinqContract)
{
@@ -371,11 +360,11 @@ namespace Newtonsoft.Json.Serialization
}
}
private void SerializeList(JsonWriter writer, IList values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
{
contract.InvokeOnSerializing(values, Serializer.Context);
contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);
SerializeStack.Add(values);
SerializeStack.Add(values.UnderlyingCollection);
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, collectionValueContract);
@@ -387,11 +376,11 @@ namespace Newtonsoft.Json.Serialization
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(values));
writer.WriteValue(Serializer.ReferenceResolver.GetReference(values.UnderlyingCollection));
}
if (includeTypeDetails)
{
WriteTypeProperty(writer, values.GetType());
WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
}
writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
}
@@ -402,11 +391,12 @@ namespace Newtonsoft.Json.Serialization
int initialDepth = writer.Top;
for (int i = 0; i < values.Count; i++)
int index = 0;
// note that an error in the IEnumerable won't be caught
foreach (object value in values)
{
try
{
object value = values[i];
JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
@@ -415,19 +405,23 @@ namespace Newtonsoft.Json.Serialization
}
else
{
if (!CheckForCircularReference(value, null, contract))
continue;
SerializeValue(writer, value, valueContract, null, childValuesContract);
if (CheckForCircularReference(value, null, contract))
{
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
}
catch (Exception ex)
{
if (IsErrorHandled(values, contract, i, ex))
if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
HandleError(writer, initialDepth);
else
throw;
}
finally
{
index++;
}
}
writer.WriteEndArray();
@@ -439,10 +433,13 @@ namespace Newtonsoft.Json.Serialization
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(values, Serializer.Context);
contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
}
#if !SILVERLIGHT && !PocketPC
#if !NET20
[SecuritySafeCritical]
#endif
private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract)
{
contract.InvokeOnSerializing(value, Serializer.Context);
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Utilities
_genericCollection = list;
}
public void Add(T item)
public virtual void Add(T item)
{
if (_genericCollection != null)
_genericCollection.Add(item);
@@ -69,7 +69,7 @@ namespace Newtonsoft.Json.Utilities
_list.Add(item);
}
public void Clear()
public virtual void Clear()
{
if (_genericCollection != null)
_genericCollection.Clear();
@@ -77,7 +77,7 @@ namespace Newtonsoft.Json.Utilities
_list.Clear();
}
public bool Contains(T item)
public virtual bool Contains(T item)
{
if (_genericCollection != null)
return _genericCollection.Contains(item);
@@ -85,7 +85,7 @@ namespace Newtonsoft.Json.Utilities
return _list.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
public virtual void CopyTo(T[] array, int arrayIndex)
{
if (_genericCollection != null)
_genericCollection.CopyTo(array, arrayIndex);
@@ -93,7 +93,7 @@ namespace Newtonsoft.Json.Utilities
_list.CopyTo(array, arrayIndex);
}
public int Count
public virtual int Count
{
get
{
@@ -104,7 +104,7 @@ namespace Newtonsoft.Json.Utilities
}
}
public bool IsReadOnly
public virtual bool IsReadOnly
{
get
{
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json.Utilities
}
}
public bool Remove(T item)
public virtual bool Remove(T item)
{
if (_genericCollection != null)
{
@@ -132,7 +132,7 @@ namespace Newtonsoft.Json.Utilities
}
}
public IEnumerator<T> GetEnumerator()
public virtual IEnumerator<T> GetEnumerator()
{
if (_genericCollection != null)
return _genericCollection.GetEnumerator();
@@ -235,7 +235,11 @@ namespace Newtonsoft.Json.Utilities
if (targetType == typeof (Uri))
return new Uri((string) initialValue);
if (targetType == typeof (TimeSpan))
return TimeSpan.Parse((string) initialValue);
#if !NET20 && !SILVERLIGHT
return TimeSpan.Parse((string) initialValue, CultureInfo.InvariantCulture);
#else
return TimeSpan.Parse((string)initialValue);
#endif
}
#if !PocketPC
+26 -122
View File
@@ -38,23 +38,21 @@ namespace Newtonsoft.Json.Utilities
object UnderlyingList { get; }
}
internal class ListWrapper<T> : IList<T>, IWrappedList
internal class ListWrapper<T> : CollectionWrapper<T>, IList<T>, IWrappedList
{
private readonly IList _list;
private readonly IList<T> _genericList;
private object _syncRoot;
public ListWrapper(IList list)
: base(list)
{
ValidationUtils.ArgumentNotNull(list, "list");
if (list is IList<T>)
_genericList = (IList<T>) list;
else
_list = list;
}
public ListWrapper(IList<T> list)
: base(list)
{
ValidationUtils.ArgumentNotNull(list, "list");
@@ -66,7 +64,7 @@ namespace Newtonsoft.Json.Utilities
if (_genericList != null)
return _genericList.IndexOf(item);
else
return _list.IndexOf(item);
return ((IList)this).IndexOf(item);
}
public void Insert(int index, T item)
@@ -74,7 +72,7 @@ namespace Newtonsoft.Json.Utilities
if (_genericList != null)
_genericList.Insert(index, item);
else
_list.Insert(index, item);
((IList)this).Insert(index, item);
}
public void RemoveAt(int index)
@@ -82,7 +80,7 @@ namespace Newtonsoft.Json.Utilities
if (_genericList != null)
_genericList.RemoveAt(index);
else
_list.RemoveAt(index);
((IList)this).RemoveAt(index);
}
public T this[int index]
@@ -92,72 +90,72 @@ namespace Newtonsoft.Json.Utilities
if (_genericList != null)
return _genericList[index];
else
return (T)_list[index];
return (T)((IList)this)[index];
}
set
{
if (_genericList != null)
_genericList[index] = value;
else
_list[index] = value;
((IList)this)[index] = value;
}
}
public void Add(T item)
public override void Add(T item)
{
if (_genericList != null)
_genericList.Add(item);
else
_list.Add(item);
base.Add(item);
}
public void Clear()
public override void Clear()
{
if (_genericList != null)
_genericList.Clear();
else
_list.Clear();
base.Clear();
}
public bool Contains(T item)
public override bool Contains(T item)
{
if (_genericList != null)
return _genericList.Contains(item);
else
return _list.Contains(item);
return base.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
public override void CopyTo(T[] array, int arrayIndex)
{
if (_genericList != null)
_genericList.CopyTo(array, arrayIndex);
else
_list.CopyTo(array, arrayIndex);
base.CopyTo(array, arrayIndex);
}
public int Count
public override int Count
{
get
{
if (_genericList != null)
return _genericList.Count;
else
return _list.Count;
return base.Count;
}
}
public bool IsReadOnly
public override bool IsReadOnly
{
get
{
if (_genericList != null)
return _genericList.IsReadOnly;
else
return _list.IsReadOnly;
return base.IsReadOnly;
}
}
public bool Remove(T item)
public override bool Remove(T item)
{
if (_genericList != null)
{
@@ -165,115 +163,21 @@ namespace Newtonsoft.Json.Utilities
}
else
{
bool contains = _list.Contains(item);
bool contains = base.Contains(item);
if (contains)
_list.Remove(item);
base.Remove(item);
return contains;
}
}
public IEnumerator<T> GetEnumerator()
public override IEnumerator<T> GetEnumerator()
{
if (_genericList != null)
return _genericList.GetEnumerator();
return _list.Cast<T>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
if (_genericList != null)
return _genericList.GetEnumerator();
else
return _list.GetEnumerator();
}
int IList.Add(object value)
{
VerifyValueType(value);
Add((T)value);
return (Count - 1);
}
bool IList.Contains(object value)
{
if (IsCompatibleObject(value))
return Contains((T)value);
return false;
}
int IList.IndexOf(object value)
{
if (IsCompatibleObject(value))
return IndexOf((T)value);
return -1;
}
void IList.Insert(int index, object value)
{
VerifyValueType(value);
Insert(index, (T)value);
}
bool IList.IsFixedSize
{
get { return false; }
}
void IList.Remove(object value)
{
if (IsCompatibleObject(value))
Remove((T)value);
}
object IList.this[int index]
{
get { return this[index]; }
set
{
VerifyValueType(value);
this[index] = (T)value;
}
}
void ICollection.CopyTo(Array array, int arrayIndex)
{
CopyTo((T[])array, arrayIndex);
}
bool ICollection.IsSynchronized
{
get { return false; }
}
object ICollection.SyncRoot
{
get
{
if (_syncRoot == null)
Interlocked.CompareExchange(ref _syncRoot, new object(), null);
return _syncRoot;
}
}
private static void VerifyValueType(object value)
{
if (!IsCompatibleObject(value))
throw new ArgumentException("The value '{0}' is not of type '{1}' and cannot be used in this generic collection.".FormatWith(CultureInfo.InvariantCulture, value, typeof(T)), "value");
}
private static bool IsCompatibleObject(object value)
{
if (!(value is T) && (value != null || (typeof(T).IsValueType && !ReflectionUtils.IsNullableType(typeof(T)))))
return false;
return true;
return base.GetEnumerator();
}
public object UnderlyingList
@@ -283,7 +187,7 @@ namespace Newtonsoft.Json.Utilities
if (_genericList != null)
return _genericList;
else
return _list;
return UnderlyingCollection;
}
}
}