-Changed Newtonsoft.Json.Net20.dll to use LinqBridge source code rather than ilmerge to fix error

This commit is contained in:
JamesNK
2011-06-25 04:10:33 +00:00
parent 857d72530c
commit ba6ec3202e
15 changed files with 3291 additions and 67 deletions
@@ -223,6 +223,15 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(1, c);
}
[Test]
public void ConvertValueToFormattableType()
{
IFormattable f = (new JValue(1).Value<IFormattable>());
Assert.AreEqual(1, f);
Assert.AreEqual("01", f.ToString("00", CultureInfo.InvariantCulture));
}
[Test]
public void Ordering()
{
@@ -63,10 +63,6 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="LinqBridge, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c2b14eb747628076, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\LinqBridge.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
+68 -2
View File
@@ -6,6 +6,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using System.Xml.Serialization;
using Newtonsoft.Json.Utilities;
using NUnit.Framework;
@@ -146,6 +147,71 @@ namespace Newtonsoft.Json.Tests
}, "JObject");
}
[Test]
public void BuildJObjectComparedToXml()
{
const long totalIterations = 100000;
const String xml =
@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
<root>
<property name=""Property1"">1</property>
<property name=""Property2"">2</property>
<property name=""Property3"">3</property>
<property name=""Property4"">4</property>
<property name=""Property5"">5</property>
</root>";
const String json =
@"{
""Property1"":""1"",
""Property2"":""2"",
""Property3"":""3"",
""Property4"":""4"",
""Property5"":""5""
}";
var watch = new Stopwatch();
watch.Start();
for (long iteration = 0; iteration < totalIterations; ++iteration)
{
var obj = JObject.Parse(json);
obj["Property1"].Value<Int32>();
obj["Property2"].Value<Int32>();
obj["Property3"].Value<Int32>();
obj["Property4"].Value<Int32>();
obj["Property5"].Value<Int32>();
}
watch.Stop();
var performance1 = (totalIterations / watch.ElapsedMilliseconds) * 1000;
Console.WriteLine("JSON: " + watch.Elapsed.TotalSeconds);
watch.Reset();
watch.Start();
for (long iteration = 0; iteration < totalIterations; ++iteration)
{
var doc = XDocument.Parse(xml);
var alarmProperties = doc.Descendants("property");
foreach (var property in alarmProperties)
{
var attr = property.Attribute("name");
var name = attr.Value;
switch (name)
{
case "Property1": Int32.Parse(property.Value); break;
case "Property2": Int32.Parse(property.Value); break;
case "Property3": Int32.Parse(property.Value); break;
case "Property4": Int32.Parse(property.Value); break;
case "Property5": Int32.Parse(property.Value); break;
}
}
}
watch.Stop();
var performance2 = (totalIterations / watch.ElapsedMilliseconds) * 1000;
Console.WriteLine("XML: " + watch.Elapsed.TotalSeconds);
}
private void SerializeSize(object value)
{
// this is extremely slow with 5000 interations
@@ -547,7 +613,7 @@ namespace Newtonsoft.Json.Tests
{
JObject test = JObject.Parse(JsonText);
IsoDateTimeConverter isoDateTimeConverter = null;// = new IsoDateTimeConverter();
MemoryStream ms = new MemoryStream();
MemoryStream ms = new MemoryStream();
TimeOperation<object>(() =>
{
@@ -559,7 +625,7 @@ namespace Newtonsoft.Json.Tests
test.WriteTo(jsonTextWriter);
jsonTextWriter.Flush();
ms.ToArray();
//Encoding.UTF8.GetBytes(test.ToString(Formatting.None));
}
return null;
@@ -41,5 +41,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.2.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.0.2.13801")]
[assembly: AssemblyFileVersion("4.0.2.13825")]
#endif
@@ -28,7 +28,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Newtonsoft.Json.Tests.Linq;
using NUnit.Framework;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Tests.TestObjects;
@@ -107,6 +109,42 @@ namespace Newtonsoft.Json.Tests.Utilities
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey) result;
Assert.AreEqual("First!", key.Value);
}
//[Test]
//public void sdfsdf()
//{
// string name = "MyAssembly";
// string filename = name + ".dll";
// AssemblyName s = new AssemblyName(name);
// AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(s, AssemblyBuilderAccess.RunAndSave);
// ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(filename, filename);
// TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Class, typeof(object));
// MethodBuilder methodBuilder = typeBuilder.DefineMethod("TestSet", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new[] { typeof(object), typeof(object) });
// DynamicReflectionDelegateFactory.GenerateCreateSetFieldIL(typeof(ClassWithGuid).GetField("GuidField"), methodBuilder.GetILGenerator());
// typeBuilder.CreateType();
// assemblyBuilder.Save(filename);
//}
//[Test]
//public void sdfsdf1()
//{
// string name = "MyAssembly1";
// string filename = name + ".dll";
// AssemblyName s = new AssemblyName(name);
// AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(s, AssemblyBuilderAccess.RunAndSave);
// ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(filename, filename);
// TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Class, typeof(object));
// MethodBuilder methodBuilder = typeBuilder.DefineMethod("TestSet", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new[] { typeof(object), typeof(object) });
// DynamicReflectionDelegateFactory.GenerateCreateSetPropertyIL(typeof(Car).GetProperty("Model"), methodBuilder.GetILGenerator());
// typeBuilder.CreateType();
// assemblyBuilder.Save(filename);
//}
}
}
#endif