-Added compact framework support
-Refactored JavaScriptConvert to not rely on DateTimeOffset when converting dates -Refactored JsonSerializer to use new CreateInstance on ReflectionUtils -Deleted JsonHandler
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Compact", "Newtonsoft.Json\Newtonsoft.Json.Compact.csproj", "{256AA604-F61B-4B6D-8D51-C8E6AB11E435}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{9ACB12BA-F27A-4BC4-A8C7-9A5B0DD02DF2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Lib\NUnitLite.dll = Lib\NUnitLite.dll
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Tests.Compact", "Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Compact.csproj", "{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -260,8 +260,10 @@ now brown cow?", '"', true);
|
||||
int i = JavaScriptConvert.DeserializeObject<int>("1");
|
||||
Assert.AreEqual(1, i);
|
||||
|
||||
#if !PocketPC
|
||||
DateTimeOffset d = JavaScriptConvert.DeserializeObject<DateTimeOffset>(@"""\/Date(-59011455539000+0000)\/""");
|
||||
Assert.AreEqual(new DateTimeOffset(new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc)), d);
|
||||
#endif
|
||||
|
||||
bool b = JavaScriptConvert.DeserializeObject<bool>("true");
|
||||
Assert.AreEqual(true, b);
|
||||
|
||||
@@ -36,7 +36,9 @@ using System.Collections.ObjectModel;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Converters;
|
||||
#if !PocketPC
|
||||
using System.Runtime.Serialization.Json;
|
||||
#endif
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
@@ -742,6 +744,7 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("Large", deserializedProductShort.Sizes[2]);
|
||||
}
|
||||
|
||||
#if !PocketPC
|
||||
[Test]
|
||||
public void Unicode()
|
||||
{
|
||||
@@ -781,6 +784,7 @@ keyword such as type of business.""
|
||||
result = JavaScriptConvert.SerializeObject(testDates);
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DateTimeOffset()
|
||||
@@ -1319,5 +1323,13 @@ keyword such as type of business.""
|
||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Assert.AreEqual(@"{}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeStringDate()
|
||||
{
|
||||
string dateText = @"""\/Date(1221644506800-0700)\/""";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,11 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
public void Casting()
|
||||
{
|
||||
Assert.AreEqual(new DateTime(2000, 12, 20), (DateTime)new JValue(new DateTime(2000, 12, 20)));
|
||||
#if !PocketPC
|
||||
Assert.AreEqual(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero), (DateTimeOffset)new JValue(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero)));
|
||||
Assert.AreEqual(null, (DateTimeOffset?)new JValue((DateTimeOffset?)null));
|
||||
Assert.AreEqual(null, (DateTimeOffset?)(JValue)null);
|
||||
#endif
|
||||
Assert.AreEqual(true, (bool)new JValue(true));
|
||||
Assert.AreEqual(true, (bool?)new JValue(true));
|
||||
Assert.AreEqual(null, (bool?)((JValue)null));
|
||||
@@ -170,9 +174,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, (int?)new JValue((int?)null));
|
||||
Assert.AreEqual(null, (int?)(JValue)null);
|
||||
Assert.AreEqual(null, (DateTime?)new JValue((DateTime?)null));
|
||||
Assert.AreEqual(null, (DateTimeOffset?)new JValue((DateTimeOffset?)null));
|
||||
Assert.AreEqual(null, (DateTime?)(JValue)null);
|
||||
Assert.AreEqual(null, (DateTimeOffset?)(JValue)null);
|
||||
Assert.AreEqual(null, (short?)new JValue((short?)null));
|
||||
Assert.AreEqual(null, (short?)(JValue)null);
|
||||
Assert.AreEqual(null, (float?)new JValue((float?)null));
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<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>{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Newtonsoft.Json.Tests.Compact</RootNamespace>
|
||||
<AssemblyName>Newtonsoft.Json.Tests.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.Tests.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\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;$(PlatformFamilyName)</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;$(PlatformFamilyName)</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="NUnitLite, Version=2.4.7.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\NUnitLite.dll</HintPath>
|
||||
</Reference>
|
||||
<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="Converters\IsoDateTimeConverterTests.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverterTest.cs" />
|
||||
<Compile Include="DateTimeTestClass.cs" />
|
||||
<Compile Include="JavaScriptConvertTest.cs" />
|
||||
<Compile Include="JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="JsonTokenReaderTest.cs" />
|
||||
<Compile Include="JsonTokenWriterTest.cs" />
|
||||
<Compile Include="Linq\JArrayTests.cs" />
|
||||
<Compile Include="Linq\JObjectTests.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
|
||||
<Compile Include="Linq\JTokenTests.cs" />
|
||||
<Compile Include="Linq\JValueTests.cs" />
|
||||
<Compile Include="Linq\LinqToJsonTest.cs" />
|
||||
<Compile Include="PerformanceTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SilverlightTests.cs" />
|
||||
<Compile Include="TestFixtureBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Compact.csproj">
|
||||
<Project>{256AA604-F61B-4B6D-8D51-C8E6AB11E435}</Project>
|
||||
<Name>Newtonsoft.Json.Compact</Name>
|
||||
</ProjectReference>
|
||||
</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>
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !SILVERLIGHT
|
||||
#if !SILVERLIGHT && !PocketPC
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -6,10 +6,12 @@ using System.Runtime.InteropServices;
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
||||
#if !SILVERLIGHT
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Tests")]
|
||||
#else
|
||||
#if SILVERLIGHT
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Tests Silverlight")]
|
||||
#elif PocketPC
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Tests Compact")]
|
||||
#else
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Tests")]
|
||||
#endif
|
||||
|
||||
[assembly: AssemblyDescription("")]
|
||||
@@ -38,4 +40,6 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("3.0.0.0")]
|
||||
#endif
|
||||
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !SILVERLIGHT
|
||||
#if !SILVERLIGHT && !PocketPC
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -120,8 +120,12 @@ namespace Newtonsoft.Json.Converters
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (typeof(DateTime).IsAssignableFrom(objectType)
|
||||
|| typeof(DateTimeOffset).IsAssignableFrom(objectType));
|
||||
if (typeof(DateTime).IsAssignableFrom(objectType))
|
||||
return true;
|
||||
if (typeof(DateTimeOffset).IsAssignableFrom(objectType))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,8 +79,12 @@ namespace Newtonsoft.Json.Converters
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (typeof(DateTime).IsAssignableFrom(objectType)
|
||||
|| typeof(DateTimeOffset).IsAssignableFrom(objectType));
|
||||
if (typeof(DateTime).IsAssignableFrom(objectType))
|
||||
return true;
|
||||
if (typeof(DateTimeOffset).IsAssignableFrom(objectType))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Linq;
|
||||
|
||||
@@ -0,0 +1,558 @@
|
||||
#if PocketPC
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
public struct DateTimeOffset : IComparable, IFormattable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>
|
||||
{
|
||||
private DateTime _dateTime;
|
||||
private short _offsetMinutes;
|
||||
internal const long MaxOffset = 0x7558bdb000L;
|
||||
public static readonly DateTimeOffset MaxValue;
|
||||
internal const long MinOffset = -504000000000L;
|
||||
public static readonly DateTimeOffset MinValue;
|
||||
|
||||
static DateTimeOffset()
|
||||
{
|
||||
MinValue = new DateTimeOffset(0L, TimeSpan.Zero);
|
||||
MaxValue = new DateTimeOffset(0x2bca2875f4373fffL, TimeSpan.Zero);
|
||||
}
|
||||
|
||||
public DateTimeOffset(System.DateTime dateTime)
|
||||
{
|
||||
TimeSpan utcOffset;
|
||||
if (dateTime.Kind != DateTimeKind.Utc)
|
||||
{
|
||||
utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
utcOffset = new TimeSpan(0L);
|
||||
}
|
||||
this._offsetMinutes = ValidateOffset(utcOffset);
|
||||
this._dateTime = ValidateDate(dateTime, utcOffset);
|
||||
}
|
||||
|
||||
public DateTimeOffset(System.DateTime dateTime, TimeSpan offset)
|
||||
{
|
||||
if (dateTime.Kind == DateTimeKind.Local)
|
||||
{
|
||||
if (offset != TimeZone.CurrentTimeZone.GetUtcOffset(dateTime))
|
||||
{
|
||||
throw new ArgumentException("The UTC Offset of the local dateTime parameter does not match the offset argument.", "offset");
|
||||
}
|
||||
}
|
||||
else if ((dateTime.Kind == DateTimeKind.Utc) && (offset != TimeSpan.Zero))
|
||||
{
|
||||
throw new ArgumentException("The UTC Offset for Utc DateTime instances must be 0.", "offset");
|
||||
}
|
||||
this._offsetMinutes = ValidateOffset(offset);
|
||||
this._dateTime = ValidateDate(dateTime, offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset(long ticks, TimeSpan offset)
|
||||
{
|
||||
this._offsetMinutes = ValidateOffset(offset);
|
||||
System.DateTime dateTime = new System.DateTime(ticks);
|
||||
this._dateTime = ValidateDate(dateTime, offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
|
||||
{
|
||||
this._offsetMinutes = ValidateOffset(offset);
|
||||
this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second), offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
|
||||
{
|
||||
this._offsetMinutes = ValidateOffset(offset);
|
||||
this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second, millisecond), offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, TimeSpan offset)
|
||||
{
|
||||
this._offsetMinutes = ValidateOffset(offset);
|
||||
this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second, millisecond, calendar), offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset Add(TimeSpan timeSpan)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.Add(timeSpan), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddDays(double days)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddDays(days), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddHours(double hours)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddHours(hours), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddMilliseconds(double milliseconds)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddMilliseconds(milliseconds), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddMinutes(double minutes)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddMinutes(minutes), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddMonths(int months)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddMonths(months), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddSeconds(double seconds)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddSeconds(seconds), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddTicks(long ticks)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddTicks(ticks), this.Offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset AddYears(int years)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.AddYears(years), this.Offset);
|
||||
}
|
||||
|
||||
public static int Compare(DateTimeOffset first, DateTimeOffset second)
|
||||
{
|
||||
return System.DateTime.Compare(first.UtcDateTime, second.UtcDateTime);
|
||||
}
|
||||
|
||||
public int CompareTo(DateTimeOffset other)
|
||||
{
|
||||
System.DateTime utcDateTime = other.UtcDateTime;
|
||||
System.DateTime time2 = this.UtcDateTime;
|
||||
if (time2 > utcDateTime)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (time2 < utcDateTime)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool Equals(DateTimeOffset other)
|
||||
{
|
||||
return this.UtcDateTime.Equals(other.UtcDateTime);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is DateTimeOffset)
|
||||
{
|
||||
DateTimeOffset offset = (DateTimeOffset)obj;
|
||||
return this.UtcDateTime.Equals(offset.UtcDateTime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Equals(DateTimeOffset first, DateTimeOffset second)
|
||||
{
|
||||
return System.DateTime.Equals(first.UtcDateTime, second.UtcDateTime);
|
||||
}
|
||||
|
||||
public bool EqualsExact(DateTimeOffset other)
|
||||
{
|
||||
return (((this.ClockDateTime == other.ClockDateTime) && (this.Offset == other.Offset)) && (this.ClockDateTime.Kind == other.ClockDateTime.Kind));
|
||||
}
|
||||
|
||||
public static DateTimeOffset FromFileTime(long fileTime)
|
||||
{
|
||||
return new DateTimeOffset(System.DateTime.FromFileTime(fileTime));
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.UtcDateTime.GetHashCode();
|
||||
}
|
||||
|
||||
public static DateTimeOffset operator +(DateTimeOffset dateTimeTz, TimeSpan timeSpan)
|
||||
{
|
||||
return new DateTimeOffset(dateTimeTz.ClockDateTime + timeSpan, dateTimeTz.Offset);
|
||||
}
|
||||
|
||||
public static bool operator ==(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime == right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static bool operator >(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime > right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static bool operator >=(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime >= right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static implicit operator DateTimeOffset(System.DateTime dateTime)
|
||||
{
|
||||
return new DateTimeOffset(dateTime);
|
||||
}
|
||||
|
||||
public static bool operator !=(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime != right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static bool operator <(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime < right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static bool operator <=(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (left.UtcDateTime <= right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static TimeSpan operator -(DateTimeOffset left, DateTimeOffset right)
|
||||
{
|
||||
return (TimeSpan)(left.UtcDateTime - right.UtcDateTime);
|
||||
}
|
||||
|
||||
public static DateTimeOffset operator -(DateTimeOffset dateTimeTz, TimeSpan timeSpan)
|
||||
{
|
||||
return new DateTimeOffset(dateTimeTz.ClockDateTime - timeSpan, dateTimeTz.Offset);
|
||||
}
|
||||
|
||||
public static DateTimeOffset Parse(string input)
|
||||
{
|
||||
return new DateTimeOffset(DateTime.Parse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None));
|
||||
}
|
||||
|
||||
public static DateTimeOffset Parse(string input, IFormatProvider formatProvider)
|
||||
{
|
||||
return Parse(input, formatProvider, DateTimeStyles.None);
|
||||
}
|
||||
|
||||
public static DateTimeOffset Parse(string input, IFormatProvider formatProvider, DateTimeStyles styles)
|
||||
{
|
||||
styles = ValidateStyles(styles, "styles");
|
||||
return new DateTimeOffset(DateTime.Parse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles));
|
||||
}
|
||||
|
||||
public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider)
|
||||
{
|
||||
return ParseExact(input, format, formatProvider, DateTimeStyles.None);
|
||||
}
|
||||
|
||||
public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles)
|
||||
{
|
||||
styles = ValidateStyles(styles, "styles");
|
||||
return new DateTimeOffset(DateTime.ParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles));
|
||||
}
|
||||
|
||||
public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles)
|
||||
{
|
||||
styles = ValidateStyles(styles, "styles");
|
||||
return new DateTimeOffset(DateTime.ParseExact(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles));
|
||||
}
|
||||
|
||||
public TimeSpan Subtract(DateTimeOffset value)
|
||||
{
|
||||
return this.UtcDateTime.Subtract(value.UtcDateTime);
|
||||
}
|
||||
|
||||
public DateTimeOffset Subtract(TimeSpan value)
|
||||
{
|
||||
return new DateTimeOffset(this.ClockDateTime.Subtract(value), this.Offset);
|
||||
}
|
||||
|
||||
int IComparable.CompareTo(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (!(obj is DateTimeOffset))
|
||||
{
|
||||
throw new ArgumentException("Object must be of type DateTimeOffset.");
|
||||
}
|
||||
DateTimeOffset offset = (DateTimeOffset)obj;
|
||||
System.DateTime utcDateTime = offset.UtcDateTime;
|
||||
System.DateTime time2 = this.UtcDateTime;
|
||||
if (time2 > utcDateTime)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (time2 < utcDateTime)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long ToFileTime()
|
||||
{
|
||||
return this.UtcDateTime.ToFileTime();
|
||||
}
|
||||
|
||||
public DateTimeOffset ToLocalTime()
|
||||
{
|
||||
return new DateTimeOffset(this.UtcDateTime.ToLocalTime());
|
||||
}
|
||||
|
||||
public DateTimeOffset ToOffset(TimeSpan offset)
|
||||
{
|
||||
System.DateTime time = this._dateTime + offset;
|
||||
return new DateTimeOffset(time.Ticks, offset);
|
||||
}
|
||||
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return DateTimeFormat.Format(this.ClockDateTime, null, DateTimeFormatInfo.CurrentInfo, this.Offset);
|
||||
//}
|
||||
|
||||
//public string ToString(IFormatProvider formatProvider)
|
||||
//{
|
||||
// return DateTimeFormat.Format(this.ClockDateTime, null, DateTimeFormatInfo.GetInstance(formatProvider), this.Offset);
|
||||
//}
|
||||
|
||||
//public string ToString(string format)
|
||||
//{
|
||||
// return DateTimeFormat.Format(this.ClockDateTime, format, DateTimeFormatInfo.CurrentInfo, this.Offset);
|
||||
//}
|
||||
|
||||
//public string ToString(string format, IFormatProvider formatProvider)
|
||||
//{
|
||||
// return DateTimeFormat.Format(this.ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), this.Offset);
|
||||
//}
|
||||
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(format))
|
||||
{
|
||||
format = format.Replace("K", "zzz");
|
||||
format = format.Replace("zzz", Offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + Offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture));
|
||||
format = format.Replace("zz", Offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture));
|
||||
format = format.Replace("z", Offset.Hours.ToString("+0;-0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
return ClockDateTime.ToString(format, formatProvider);
|
||||
}
|
||||
|
||||
public DateTimeOffset ToUniversalTime()
|
||||
{
|
||||
return new DateTimeOffset(this.UtcDateTime);
|
||||
}
|
||||
|
||||
private static System.DateTime ValidateDate(System.DateTime dateTime, TimeSpan offset)
|
||||
{
|
||||
long ticks = dateTime.Ticks - offset.Ticks;
|
||||
if ((ticks < 0L) || (ticks > 0x2bca2875f4373fffL))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset", "The UTC time represented when the offset is applied must be between year 0 and 10,000.");
|
||||
}
|
||||
return new System.DateTime(ticks, DateTimeKind.Unspecified);
|
||||
}
|
||||
|
||||
private static short ValidateOffset(TimeSpan offset)
|
||||
{
|
||||
long ticks = offset.Ticks;
|
||||
if ((ticks % 0x23c34600L) != 0L)
|
||||
{
|
||||
throw new ArgumentException("Offset must be specified in whole minutes.", "offset");
|
||||
}
|
||||
if ((ticks < -504000000000L) || (ticks > 0x7558bdb000L))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset", "Offset must be within plus or minus 14 hours.");
|
||||
}
|
||||
return (short)(offset.Ticks / 0x23c34600L);
|
||||
}
|
||||
|
||||
private static DateTimeStyles ValidateStyles(DateTimeStyles style, string parameterName)
|
||||
{
|
||||
if ((style & ~(DateTimeStyles.RoundtripKind | DateTimeStyles.AssumeUniversal | DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal | DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AllowWhiteSpaces)) != DateTimeStyles.None)
|
||||
{
|
||||
throw new ArgumentException("An undefined DateTimeStyles value is being used.", parameterName);
|
||||
}
|
||||
if (((style & DateTimeStyles.AssumeLocal) != DateTimeStyles.None) && ((style & DateTimeStyles.AssumeUniversal) != DateTimeStyles.None))
|
||||
{
|
||||
throw new ArgumentException("The DateTimeStyles values AssumeLocal and AssumeUniversal cannot be used together.", parameterName);
|
||||
}
|
||||
if ((style & DateTimeStyles.NoCurrentDateDefault) != DateTimeStyles.None)
|
||||
{
|
||||
throw new ArgumentException("The DateTimeStyles value 'NoCurrentDateDefault' is not allowed when parsing DateTimeOffset.", parameterName);
|
||||
}
|
||||
style &= ~DateTimeStyles.RoundtripKind;
|
||||
style &= ~DateTimeStyles.AssumeLocal;
|
||||
return style;
|
||||
}
|
||||
|
||||
private System.DateTime ClockDateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
System.DateTime time = this._dateTime + this.Offset;
|
||||
return new System.DateTime(time.Ticks, DateTimeKind.Unspecified);
|
||||
}
|
||||
}
|
||||
|
||||
public System.DateTime Date
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Date;
|
||||
}
|
||||
}
|
||||
|
||||
public System.DateTime DateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime;
|
||||
}
|
||||
}
|
||||
|
||||
public int Day
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Day;
|
||||
}
|
||||
}
|
||||
|
||||
public System.DayOfWeek DayOfWeek
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.DayOfWeek;
|
||||
}
|
||||
}
|
||||
|
||||
public int DayOfYear
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.DayOfYear;
|
||||
}
|
||||
}
|
||||
|
||||
public int Hour
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Hour;
|
||||
}
|
||||
}
|
||||
|
||||
public System.DateTime LocalDateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UtcDateTime.ToLocalTime();
|
||||
}
|
||||
}
|
||||
|
||||
public int Millisecond
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Millisecond;
|
||||
}
|
||||
}
|
||||
|
||||
public int Minute
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Minute;
|
||||
}
|
||||
}
|
||||
|
||||
public int Month
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Month;
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTimeOffset Now
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DateTimeOffset(System.DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Offset
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TimeSpan(0, this._offsetMinutes, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public int Second
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Second;
|
||||
}
|
||||
}
|
||||
|
||||
public long Ticks
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Ticks;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan TimeOfDay
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.TimeOfDay;
|
||||
}
|
||||
}
|
||||
|
||||
public System.DateTime UtcDateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.DateTime.SpecifyKind(this._dateTime, DateTimeKind.Utc);
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTimeOffset UtcNow
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DateTimeOffset(System.DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
|
||||
public long UtcTicks
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UtcDateTime.Ticks;
|
||||
}
|
||||
}
|
||||
|
||||
public int Year
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClockDateTime.Year;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -101,7 +101,14 @@ namespace Newtonsoft.Json
|
||||
/// <returns>A Json string representation of the <see cref="DateTime"/>.</returns>
|
||||
public static string ToString(DateTime value)
|
||||
{
|
||||
return ToStringInternal(new DateTimeOffset(value), value.Kind);
|
||||
TimeSpan utcOffset;
|
||||
#if PocketPC
|
||||
utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(value);
|
||||
#else
|
||||
utcOffset = TimeZoneInfo.Local.GetUtcOffset(value);
|
||||
#endif
|
||||
|
||||
return ToStringInternal(value, utcOffset, value.Kind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,31 +118,30 @@ namespace Newtonsoft.Json
|
||||
/// <returns>A Json string representation of the <see cref="DateTimeOffset"/>.</returns>
|
||||
public static string ToString(DateTimeOffset value)
|
||||
{
|
||||
return ToStringInternal(value, DateTimeKind.Local);
|
||||
return ToStringInternal(value.UtcDateTime, value.Offset, DateTimeKind.Local);
|
||||
}
|
||||
|
||||
internal static string ToStringInternal(DateTimeOffset value, DateTimeKind kind)
|
||||
internal static string ToStringInternal(DateTime value, TimeSpan offset, DateTimeKind kind)
|
||||
{
|
||||
long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value);
|
||||
|
||||
string offset;
|
||||
string timezoneOffset;
|
||||
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);
|
||||
timezoneOffset = offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
|
||||
break;
|
||||
default:
|
||||
offset = string.Empty;
|
||||
timezoneOffset = string.Empty;
|
||||
break;
|
||||
}
|
||||
return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + offset + @")\/""";
|
||||
return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + timezoneOffset + @")\/""";
|
||||
}
|
||||
|
||||
internal static long ConvertDateTimeToJavaScriptTicks(DateTimeOffset dateTime)
|
||||
internal static long ConvertDateTimeToJavaScriptTicks(DateTime dateTime)
|
||||
{
|
||||
DateTimeOffset utcDateTime = dateTime.ToUniversalTime();
|
||||
DateTime utcDateTime = dateTime.ToUniversalTime();
|
||||
|
||||
//if (utcDateTime < MinimumJavaScriptDate)
|
||||
// utcDateTime = MinimumJavaScriptDate;
|
||||
|
||||
@@ -1,90 +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.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<JsonWriter> 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<JsonWriter>(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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -625,7 +625,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
newObject = Activator.CreateInstance(objectType, constructorParameters.Values.ToArray());
|
||||
newObject = ReflectionUtils.CreateInstance(objectType, constructorParameters.Values.ToArray());
|
||||
|
||||
return newObject;
|
||||
}
|
||||
@@ -804,7 +804,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
Type objectType = value.GetType();
|
||||
|
||||
#if !SILVERLIGHT
|
||||
#if !SILVERLIGHT && !PocketPC
|
||||
TypeConverter converter = TypeDescriptor.GetConverter(objectType);
|
||||
|
||||
// use the objectType's TypeConverter if it has one and can convert to a string
|
||||
|
||||
@@ -199,7 +199,9 @@ namespace Newtonsoft.Json.Linq
|
||||
return JsonTokenType.Integer;
|
||||
else if (value is double || value is float || value is decimal)
|
||||
return JsonTokenType.Float;
|
||||
else if (value is DateTime || value is DateTimeOffset)
|
||||
else if (value is DateTime)
|
||||
return JsonTokenType.Date;
|
||||
else if (value is DateTimeOffset)
|
||||
return JsonTokenType.Date;
|
||||
else if (value is bool)
|
||||
return JsonTokenType.Boolean;
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<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.Compact</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\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;$(PlatformFamilyName)</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;$(PlatformFamilyName)</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</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="Converters\HtmlColorConverter.cs" />
|
||||
<Compile Include="Converters\IsoDateTimeConverter.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverter.cs" />
|
||||
<Compile Include="Converters\JsonDateTimeSerializationMode.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverter.cs" />
|
||||
<Compile Include="DateTimeOffset.cs" />
|
||||
<Compile Include="DefaultValueHandling.cs" />
|
||||
<Compile Include="Identifier.cs" />
|
||||
<Compile Include="JavaScriptConvert.cs" />
|
||||
<Compile Include="JsonConverter.cs" />
|
||||
<Compile Include="JsonConverterAttribute.cs" />
|
||||
<Compile Include="JsonConverterCollection.cs" />
|
||||
<Compile Include="JsonIgnoreAttribute.cs" />
|
||||
<Compile Include="JsonObjectAttribute.cs" />
|
||||
<Compile Include="JsonPropertyAttribute.cs" />
|
||||
<Compile Include="JsonReader.cs" />
|
||||
<Compile Include="JsonReaderException.cs" />
|
||||
<Compile Include="JsonSerializationException.cs" />
|
||||
<Compile Include="JsonSerializer.cs" />
|
||||
<Compile Include="JsonSerializerSettings.cs" />
|
||||
<Compile Include="JsonTextReader.cs" />
|
||||
<Compile Include="JsonTextWriter.cs" />
|
||||
<Compile Include="JsonToken.cs" />
|
||||
<Compile Include="JsonWriter.cs" />
|
||||
<Compile Include="JsonWriterException.cs" />
|
||||
<Compile Include="Linq\Extensions.cs" />
|
||||
<Compile Include="Linq\IJEnumerable.cs" />
|
||||
<Compile Include="Linq\JArray.cs" />
|
||||
<Compile Include="Linq\JConstructor.cs" />
|
||||
<Compile Include="Linq\JContainer.cs" />
|
||||
<Compile Include="Linq\JEnumerable.cs" />
|
||||
<Compile Include="Linq\JObject.cs" />
|
||||
<Compile Include="Linq\JProperty.cs" />
|
||||
<Compile Include="Linq\JsonTokenReader.cs" />
|
||||
<Compile Include="Linq\JsonTokenType.cs" />
|
||||
<Compile Include="Linq\JsonTokenWriter.cs" />
|
||||
<Compile Include="Linq\JToken.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
||||
<Compile Include="Linq\JValue.cs" />
|
||||
<Compile Include="MemberMapping.cs" />
|
||||
<Compile Include="MemberMappingCollection.cs" />
|
||||
<Compile Include="MemberSerialization.cs" />
|
||||
<Compile Include="MissingMemberHandling.cs" />
|
||||
<Compile Include="NullValueHandling.cs" />
|
||||
<Compile Include="ObjectCreationHandling.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ReferenceLoopHandling.cs" />
|
||||
<Compile Include="StringBuffer.cs" />
|
||||
<Compile Include="Utilities\CollectionUtils.cs" />
|
||||
<Compile Include="Utilities\CollectionWrapper.cs" />
|
||||
<Compile Include="Utilities\ConvertUtils.cs" />
|
||||
<Compile Include="Utilities\DateTimeUtils.cs" />
|
||||
<Compile Include="Utilities\DictionaryWrapper.cs" />
|
||||
<Compile Include="Utilities\JavaScriptUtils.cs" />
|
||||
<Compile Include="Utilities\ListWrapper.cs" />
|
||||
<Compile Include="Utilities\MathUtils.cs" />
|
||||
<Compile Include="Utilities\MiscellaneousUtils.cs" />
|
||||
<Compile Include="Utilities\ReflectionUtils.cs" />
|
||||
<Compile Include="Utilities\StringUtils.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>
|
||||
@@ -78,9 +78,6 @@
|
||||
<Compile Include="..\Newtonsoft.Json\JsonConverterCollection.cs">
|
||||
<Link>JsonConverterCollection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Newtonsoft.Json\JsonHandler.cs">
|
||||
<Link>JsonHandler.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Newtonsoft.Json\JsonIgnoreAttribute.cs">
|
||||
<Link>JsonIgnoreAttribute.cs</Link>
|
||||
</Compile>
|
||||
@@ -224,7 +221,6 @@
|
||||
<Compile Include="JsonConverter.cs" />
|
||||
<Compile Include="JsonConverterAttribute.cs" />
|
||||
<Compile Include="JsonConverterCollection.cs" />
|
||||
<Compile Include="JsonHandler.cs" />
|
||||
<Compile Include="JsonIgnoreAttribute.cs" />
|
||||
<Compile Include="JsonObjectAttribute.cs" />
|
||||
<Compile Include="JsonPropertyAttribute.cs" />
|
||||
|
||||
@@ -25,13 +25,16 @@ using System.Security;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
#if !SILVERLIGHT
|
||||
#if SILVERLIGHT
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")]
|
||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Silverlight")]
|
||||
#elif PocketPC
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Compact")]
|
||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact")]
|
||||
#else
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET")]
|
||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests")]
|
||||
[assembly: AllowPartiallyTrustedCallers]
|
||||
#else
|
||||
[assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")]
|
||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Silverlight")]
|
||||
#endif
|
||||
|
||||
|
||||
@@ -62,4 +65,6 @@ 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.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("3.0.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("3.0.0.0")]
|
||||
#endif
|
||||
@@ -523,7 +523,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (listType.IsArray)
|
||||
list = ToArray(((List<object>)list).ToArray(), ReflectionUtils.GetCollectionItemType(listType));
|
||||
else if (ReflectionUtils.InheritsGenericClassDefinition(listType, typeof(ReadOnlyCollection<>)))
|
||||
list = (IList)Activator.CreateInstance(listType, list);
|
||||
list = (IList)ReflectionUtils.CreateInstance(listType, list);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (initialValue is string && targetType == typeof(Guid))
|
||||
return new Guid((string)initialValue);
|
||||
|
||||
#if !PocketPC
|
||||
// see if source or target types have a TypeConverter that converts between the two
|
||||
TypeConverter toConverter = GetConverter(initialType);
|
||||
|
||||
@@ -124,6 +125,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return fromConverter.ConvertFrom(initialValue);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// handle DBNull and INullable
|
||||
if (initialValue == DBNull.Value)
|
||||
@@ -330,6 +332,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PocketPC
|
||||
private static TypeConverter GetConverter(Type t)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(t, "t");
|
||||
@@ -345,6 +348,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return (Activator.CreateInstance(Type.GetType(typeConverterAttribute.ConverterTypeName)) as TypeConverter);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public static bool IsInteger(object value)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,12 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
public static string GetLocalOffset(this DateTime d)
|
||||
{
|
||||
TimeSpan utcOffset = TimeZoneInfo.Local.GetUtcOffset(d);
|
||||
TimeSpan utcOffset;
|
||||
#if PocketPC
|
||||
utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(d);
|
||||
#else
|
||||
utcOffset = TimeZoneInfo.Local.GetUtcOffset(d);
|
||||
#endif
|
||||
|
||||
return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
@@ -35,51 +35,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetDescription(object value, out string description)
|
||||
{
|
||||
return TryAction<string>(delegate { return GetDescription(value); }, out description);
|
||||
}
|
||||
|
||||
public static string GetDescription(object o)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(o, "o");
|
||||
|
||||
ICustomAttributeProvider attributeProvider = o as ICustomAttributeProvider;
|
||||
|
||||
// object passed in isn't an attribute provider
|
||||
// if value is an enum value, get value field member, otherwise get values type
|
||||
if (attributeProvider == null)
|
||||
{
|
||||
Type valueType = o.GetType();
|
||||
|
||||
if (valueType.IsEnum)
|
||||
attributeProvider = valueType.GetField(o.ToString());
|
||||
else
|
||||
attributeProvider = valueType;
|
||||
}
|
||||
|
||||
DescriptionAttribute descriptionAttribute = ReflectionUtils.GetAttribute<DescriptionAttribute>(attributeProvider);
|
||||
|
||||
if (descriptionAttribute != null)
|
||||
return descriptionAttribute.Description;
|
||||
else
|
||||
throw new Exception("No DescriptionAttribute on '{0}'.".FormatWith(CultureInfo.InvariantCulture, o.GetType()));
|
||||
}
|
||||
|
||||
public static IList<string> GetDescriptions(IList values)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(values, "values");
|
||||
|
||||
string[] descriptions = new string[values.Count];
|
||||
|
||||
for (int i = 0; i < values.Count; i++)
|
||||
{
|
||||
descriptions[i] = GetDescription(values[i]);
|
||||
}
|
||||
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
public static string ToString(object value)
|
||||
{
|
||||
if (value == null)
|
||||
|
||||
@@ -381,21 +381,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
return (property.GetIndexParameters().Length > 0);
|
||||
}
|
||||
|
||||
public static MemberInfo GetMember(Type type, string name, MemberTypes memberTypes)
|
||||
{
|
||||
return GetMember(type, name, memberTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
public static MemberInfo GetMember(Type type, string name, MemberTypes memberTypes, BindingFlags bindingAttr)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
ValidationUtils.ArgumentNotNull(name, "name");
|
||||
|
||||
MemberInfo[] result = type.GetMember(name, memberTypes, bindingAttr);
|
||||
|
||||
return CollectionUtils.GetSingleItem<MemberInfo>(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the member's value on the object.
|
||||
/// </summary>
|
||||
@@ -565,29 +550,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
return t.FullName + ", " + t.Assembly.GetName().Name;
|
||||
}
|
||||
|
||||
public static List<MemberInfo> FindMembers(Type targetType, MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, object filterCriteria)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(targetType, "targetType");
|
||||
|
||||
List<MemberInfo> memberInfos = new List<MemberInfo>(targetType.FindMembers(memberType, bindingAttr, filter, filterCriteria));
|
||||
|
||||
// fix weirdness with FieldInfos only being returned for the current Type
|
||||
// find base type fields and add them to result
|
||||
if ((memberType & MemberTypes.Field) != 0
|
||||
&& (bindingAttr & BindingFlags.NonPublic) != 0)
|
||||
{
|
||||
// modify flags to not search for public fields
|
||||
BindingFlags nonPublicBindingAttr = bindingAttr ^ BindingFlags.Public;
|
||||
|
||||
while ((targetType = targetType.BaseType) != null)
|
||||
{
|
||||
memberInfos.AddRange(targetType.FindMembers(MemberTypes.Field, nonPublicBindingAttr, filter, filterCriteria));
|
||||
}
|
||||
}
|
||||
|
||||
return memberInfos;
|
||||
}
|
||||
|
||||
public static Type MakeGenericType(Type genericTypeDefinition, params Type[] innerTypes)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition");
|
||||
@@ -604,7 +566,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
public static object CreateGeneric(Type genericTypeDefinition, IList<Type> innerTypes, params object[] args)
|
||||
{
|
||||
return CreateGeneric(genericTypeDefinition, innerTypes, (t, a) => Activator.CreateInstance(t, a.ToArray()), args);
|
||||
return CreateGeneric(genericTypeDefinition, innerTypes, (t, a) => ReflectionUtils.CreateInstance(t, a.ToArray()), args);
|
||||
}
|
||||
|
||||
public static object CreateGeneric(Type genericTypeDefinition, IList<Type> innerTypes, Func<Type, IList<object>, object> instanceCreator, params object[] args)
|
||||
@@ -617,5 +579,58 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
return instanceCreator(specificType, args);
|
||||
}
|
||||
|
||||
static object CreateInstance(this Assembly a, string typeName, params object[] pars)
|
||||
{
|
||||
var t = a.GetType(typeName);
|
||||
var c = t.GetConstructor(pars.Select(p => p.GetType()).ToArray());
|
||||
if (c == null)
|
||||
return null;
|
||||
return c.Invoke(pars);
|
||||
}
|
||||
|
||||
public static bool IsCompatibleValue(object value, Type type)
|
||||
{
|
||||
if (value == null && IsNullable(type))
|
||||
return true;
|
||||
|
||||
if (type.IsAssignableFrom(value.GetType()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static object CreateInstance(Type type, params object[] args)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
|
||||
#if !PocketPC
|
||||
return Activator.CreateInstance(type, args);
|
||||
#else
|
||||
ConstructorInfo[] constructors = type.GetConstructors();
|
||||
ConstructorInfo match = constructors.Where(c =>
|
||||
{
|
||||
ParameterInfo[] parameters = c.GetParameters();
|
||||
if (parameters.Length != args.Length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
ParameterInfo parameter = parameters[i];
|
||||
object value = args[i];
|
||||
|
||||
if (!IsCompatibleValue(value, parameter.ParameterType))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}).FirstOrDefault();
|
||||
|
||||
if (match == null)
|
||||
throw new Exception("Could not create '{0}' with given parameters.".FormatWith(CultureInfo.InvariantCulture, args));
|
||||
|
||||
return match.Invoke(args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user