-Changed Newtonsoft.Json.Net20.dll to use LinqBridge source code rather than ilmerge to fix error
This commit is contained in:
+1
-13
@@ -58,20 +58,8 @@ task Build -depends Clean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Merge LinqBridge into .NET 2.0 build
|
|
||||||
task Merge -depends Build {
|
|
||||||
$binaryDir = "$sourceDir\Newtonsoft.Json\bin\Release\Net20"
|
|
||||||
MergeAssembly "$binaryDir\Newtonsoft.Json.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
|
|
||||||
del $binaryDir\LinqBridge.dll
|
|
||||||
|
|
||||||
$binaryDir = "$sourceDir\Newtonsoft.Json.Tests\bin\Release\Net20"
|
|
||||||
MergeAssembly "$binaryDir\Newtonsoft.Json.Tests.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
|
|
||||||
MergeAssembly "$binaryDir\Newtonsoft.Json.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
|
|
||||||
del $binaryDir\LinqBridge.dll
|
|
||||||
}
|
|
||||||
|
|
||||||
# Optional build documentation, add files to final zip
|
# Optional build documentation, add files to final zip
|
||||||
task Package -depends Merge {
|
task Package -depends Build {
|
||||||
foreach ($build in $builds)
|
foreach ($build in $builds)
|
||||||
{
|
{
|
||||||
$name = $build.TestsName
|
$name = $build.TestsName
|
||||||
|
|||||||
Binary file not shown.
@@ -3,7 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00
|
|||||||
# Visual Studio 2010
|
# Visual Studio 2010
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
Lib\LinqBridge.dll = Lib\LinqBridge.dll
|
|
||||||
Lib\NUnit\DotNet\nunit.framework.dll = Lib\NUnit\DotNet\nunit.framework.dll
|
Lib\NUnit\DotNet\nunit.framework.dll = Lib\NUnit\DotNet\nunit.framework.dll
|
||||||
Lib\NUnit\DotNet\nunit.framework.xml = Lib\NUnit\DotNet\nunit.framework.xml
|
Lib\NUnit\DotNet\nunit.framework.xml = Lib\NUnit\DotNet\nunit.framework.xml
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
|
|||||||
@@ -223,6 +223,15 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
Assert.AreEqual(1, c);
|
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]
|
[Test]
|
||||||
public void Ordering()
|
public void Ordering()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,10 +63,6 @@
|
|||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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">
|
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
|
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Web.Script.Serialization;
|
using System.Web.Script.Serialization;
|
||||||
|
using System.Xml.Linq;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@@ -146,6 +147,71 @@ namespace Newtonsoft.Json.Tests
|
|||||||
}, "JObject");
|
}, "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)
|
private void SerializeSize(object value)
|
||||||
{
|
{
|
||||||
// this is extremely slow with 5000 interations
|
// this is extremely slow with 5000 interations
|
||||||
@@ -547,7 +613,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
{
|
{
|
||||||
JObject test = JObject.Parse(JsonText);
|
JObject test = JObject.Parse(JsonText);
|
||||||
IsoDateTimeConverter isoDateTimeConverter = null;// = new IsoDateTimeConverter();
|
IsoDateTimeConverter isoDateTimeConverter = null;// = new IsoDateTimeConverter();
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
|
|
||||||
TimeOperation<object>(() =>
|
TimeOperation<object>(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ using System.Runtime.InteropServices;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.0.2.0")]
|
[assembly: AssemblyVersion("4.0.2.0")]
|
||||||
#if !PocketPC
|
#if !PocketPC
|
||||||
[assembly: AssemblyFileVersion("4.0.2.13801")]
|
[assembly: AssemblyFileVersion("4.0.2.13825")]
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Reflection.Emit;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Newtonsoft.Json.Tests.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
@@ -107,6 +109,42 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey) result;
|
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey) result;
|
||||||
Assert.AreEqual("First!", key.Value);
|
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
|
#endif
|
||||||
@@ -236,33 +236,26 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, "source");
|
||||||
|
|
||||||
bool cast = typeof(JToken).IsAssignableFrom(typeof(U));
|
|
||||||
|
|
||||||
foreach (JToken token in source)
|
foreach (JToken token in source)
|
||||||
{
|
{
|
||||||
yield return Convert<JToken, U>(token, cast);
|
yield return Convert<JToken, U>(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static U Convert<T, U>(this T token) where T : JToken
|
internal static U Convert<T, U>(this T token) where T : JToken
|
||||||
{
|
{
|
||||||
bool cast = typeof(JToken).IsAssignableFrom(typeof(U));
|
if (token == null)
|
||||||
|
return default(U);
|
||||||
|
|
||||||
return Convert<T, U>(token, cast);
|
if (token is U
|
||||||
}
|
// don't want to cast JValue to its interfaces, want to get the internal value
|
||||||
|
&& typeof(U) != typeof(IComparable) && typeof(U) != typeof(IFormattable))
|
||||||
internal static U Convert<T, U>(this T token, bool cast) where T : JToken
|
|
||||||
{
|
|
||||||
if (cast)
|
|
||||||
{
|
{
|
||||||
// HACK
|
// HACK
|
||||||
return (U)(object)token;
|
return (U)(object)token;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (token == null)
|
|
||||||
return default(U);
|
|
||||||
|
|
||||||
JValue value = token as JValue;
|
JValue value = token as JValue;
|
||||||
if (value == null)
|
if (value == null)
|
||||||
throw new InvalidCastException("Cannot cast {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, token.GetType(), typeof(T)));
|
throw new InvalidCastException("Cannot cast {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, token.GetType(), typeof(T)));
|
||||||
|
|||||||
@@ -306,9 +306,11 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reader.TokenType != JsonToken.StartObject)
|
if (reader.TokenType != JsonToken.StartObject)
|
||||||
throw new Exception(
|
{
|
||||||
"Error reading JObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(
|
throw new Exception(
|
||||||
CultureInfo.InvariantCulture, reader.TokenType));
|
"Error reading JObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(
|
||||||
|
CultureInfo.InvariantCulture, reader.TokenType));
|
||||||
|
}
|
||||||
|
|
||||||
JObject o = new JObject();
|
JObject o = new JObject();
|
||||||
o.SetLineInfo(reader as IJsonLineInfo);
|
o.SetLineInfo(reader as IJsonLineInfo);
|
||||||
|
|||||||
@@ -68,10 +68,6 @@
|
|||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
@@ -96,6 +92,7 @@
|
|||||||
<Compile Include="Converters\RegexConverter.cs" />
|
<Compile Include="Converters\RegexConverter.cs" />
|
||||||
<Compile Include="Converters\StringEnumConverter.cs" />
|
<Compile Include="Converters\StringEnumConverter.cs" />
|
||||||
<Compile Include="JsonConstructorAttribute.cs" />
|
<Compile Include="JsonConstructorAttribute.cs" />
|
||||||
|
<Compile Include="Utilities\LinqBridge.cs" />
|
||||||
<Compile Include="Linq\JPath.cs" />
|
<Compile Include="Linq\JPath.cs" />
|
||||||
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
<Compile Include="Linq\JPropertyDescriptor.cs" />
|
||||||
<Compile Include="Linq\JRaw.cs" />
|
<Compile Include="Linq\JRaw.cs" />
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.0.2.0")]
|
[assembly: AssemblyVersion("4.0.2.0")]
|
||||||
#if !PocketPC
|
#if !PocketPC
|
||||||
[assembly: AssemblyFileVersion("4.0.2.13801")]
|
[assembly: AssemblyFileVersion("4.0.2.13825")]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
@@ -338,6 +338,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
{
|
{
|
||||||
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
|
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
|
||||||
new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess).Demand();
|
new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess).Demand();
|
||||||
|
new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
|
||||||
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
|
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
|
||||||
new SecurityPermission(PermissionState.Unrestricted).Demand();
|
new SecurityPermission(PermissionState.Unrestricted).Demand();
|
||||||
_dynamicCodeGeneration = true;
|
_dynamicCodeGeneration = true;
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
DynamicMethod dynamicMethod = CreateDynamicMethod(method.ToString(), typeof(object), new[] { typeof(object), typeof(object[]) }, method.DeclaringType);
|
DynamicMethod dynamicMethod = CreateDynamicMethod(method.ToString(), typeof(object), new[] { typeof(object), typeof(object[]) }, method.DeclaringType);
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateMethodCallIL(method, generator);
|
||||||
|
|
||||||
|
return (MethodCall<T, object>)dynamicMethod.CreateDelegate(typeof(MethodCall<T, object>));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateCreateMethodCallIL(MethodBase method, ILGenerator generator)
|
||||||
|
{
|
||||||
ParameterInfo[] args = method.GetParameters();
|
ParameterInfo[] args = method.GetParameters();
|
||||||
|
|
||||||
Label argsOk = generator.DefineLabel();
|
Label argsOk = generator.DefineLabel();
|
||||||
@@ -84,8 +91,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
generator.CallMethod((MethodInfo)method);
|
generator.CallMethod((MethodInfo)method);
|
||||||
|
|
||||||
Type returnType = method.IsConstructor
|
Type returnType = method.IsConstructor
|
||||||
? method.DeclaringType
|
? method.DeclaringType
|
||||||
: ((MethodInfo)method).ReturnType;
|
: ((MethodInfo)method).ReturnType;
|
||||||
|
|
||||||
if (returnType != typeof(void))
|
if (returnType != typeof(void))
|
||||||
generator.BoxIfNeeded(returnType);
|
generator.BoxIfNeeded(returnType);
|
||||||
@@ -93,16 +100,21 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
generator.Emit(OpCodes.Ldnull);
|
generator.Emit(OpCodes.Ldnull);
|
||||||
|
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (MethodCall<T, object>)dynamicMethod.CreateDelegate(typeof(MethodCall<T, object>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<T> CreateDefaultConstructor<T>(Type type)
|
public override Func<T> CreateDefaultConstructor<T>(Type type)
|
||||||
{
|
{
|
||||||
DynamicMethod dynamicMethod = CreateDynamicMethod("Create" + type.FullName, typeof(object), Type.EmptyTypes, type);
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Create" + type.FullName, typeof(T), Type.EmptyTypes, type);
|
||||||
dynamicMethod.InitLocals = true;
|
dynamicMethod.InitLocals = true;
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateDefaultConstructorIL(type, generator);
|
||||||
|
|
||||||
|
return (Func<T>)dynamicMethod.CreateDelegate(typeof(Func<T>));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateCreateDefaultConstructorIL(Type type, ILGenerator generator)
|
||||||
|
{
|
||||||
if (type.IsValueType)
|
if (type.IsValueType)
|
||||||
{
|
{
|
||||||
generator.DeclareLocal(type);
|
generator.DeclareLocal(type);
|
||||||
@@ -122,20 +134,23 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (Func<T>)dynamicMethod.CreateDelegate(typeof(Func<T>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
||||||
|
{
|
||||||
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Get" + propertyInfo.Name, typeof(T), new[] { typeof(object) }, propertyInfo.DeclaringType);
|
||||||
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateGetPropertyIL(propertyInfo, generator);
|
||||||
|
|
||||||
|
return (Func<T, object>)dynamicMethod.CreateDelegate(typeof(Func<T, object>));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateCreateGetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
|
||||||
{
|
{
|
||||||
MethodInfo getMethod = propertyInfo.GetGetMethod(true);
|
MethodInfo getMethod = propertyInfo.GetGetMethod(true);
|
||||||
if (getMethod == null)
|
if (getMethod == null)
|
||||||
throw new Exception("Property '{0}' does not have a getter.".FormatWith(CultureInfo.InvariantCulture,
|
throw new Exception("Property '{0}' does not have a getter.".FormatWith(CultureInfo.InvariantCulture, propertyInfo.Name));
|
||||||
propertyInfo.Name));
|
|
||||||
|
|
||||||
DynamicMethod dynamicMethod = CreateDynamicMethod("Get" + propertyInfo.Name, typeof(T), new[] { typeof(object) }, propertyInfo.DeclaringType);
|
|
||||||
|
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
|
||||||
|
|
||||||
if (!getMethod.IsStatic)
|
if (!getMethod.IsStatic)
|
||||||
generator.PushInstance(propertyInfo.DeclaringType);
|
generator.PushInstance(propertyInfo.DeclaringType);
|
||||||
@@ -143,31 +158,40 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
generator.CallMethod(getMethod);
|
generator.CallMethod(getMethod);
|
||||||
generator.BoxIfNeeded(propertyInfo.PropertyType);
|
generator.BoxIfNeeded(propertyInfo.PropertyType);
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (Func<T, object>)dynamicMethod.CreateDelegate(typeof(Func<T, object>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
DynamicMethod dynamicMethod = CreateDynamicMethod("Get" + fieldInfo.Name, typeof(T), new[] { typeof(object) }, fieldInfo.DeclaringType);
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Get" + fieldInfo.Name, typeof(T), new[] { typeof(object) }, fieldInfo.DeclaringType);
|
||||||
|
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateGetFieldIL(fieldInfo, generator);
|
||||||
|
|
||||||
|
return (Func<T, object>)dynamicMethod.CreateDelegate(typeof(Func<T, object>));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateCreateGetFieldIL(FieldInfo fieldInfo, ILGenerator generator)
|
||||||
|
{
|
||||||
if (!fieldInfo.IsStatic)
|
if (!fieldInfo.IsStatic)
|
||||||
generator.PushInstance(fieldInfo.DeclaringType);
|
generator.PushInstance(fieldInfo.DeclaringType);
|
||||||
|
|
||||||
generator.Emit(OpCodes.Ldfld, fieldInfo);
|
generator.Emit(OpCodes.Ldfld, fieldInfo);
|
||||||
generator.BoxIfNeeded(fieldInfo.FieldType);
|
generator.BoxIfNeeded(fieldInfo.FieldType);
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (Func<T, object>)dynamicMethod.CreateDelegate(typeof(Func<T, object>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
DynamicMethod dynamicMethod = CreateDynamicMethod("Set" + fieldInfo.Name, null, new[] { typeof(object), typeof(object) }, fieldInfo.DeclaringType);
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Set" + fieldInfo.Name, null, new[] { typeof(T), typeof(object) }, fieldInfo.DeclaringType);
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateSetFieldIL(fieldInfo, generator);
|
||||||
|
|
||||||
|
return (Action<T, object>)dynamicMethod.CreateDelegate(typeof(Action<T, object>));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void GenerateCreateSetFieldIL(FieldInfo fieldInfo, ILGenerator generator)
|
||||||
|
{
|
||||||
if (!fieldInfo.IsStatic)
|
if (!fieldInfo.IsStatic)
|
||||||
generator.PushInstance(fieldInfo.DeclaringType);
|
generator.PushInstance(fieldInfo.DeclaringType);
|
||||||
|
|
||||||
@@ -175,16 +199,21 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
generator.UnboxIfNeeded(fieldInfo.FieldType);
|
generator.UnboxIfNeeded(fieldInfo.FieldType);
|
||||||
generator.Emit(OpCodes.Stfld, fieldInfo);
|
generator.Emit(OpCodes.Stfld, fieldInfo);
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (Action<T, object>)dynamicMethod.CreateDelegate(typeof(Action<T, object>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
MethodInfo setMethod = propertyInfo.GetSetMethod(true);
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Set" + propertyInfo.Name, null, new[] { typeof(T), typeof(object) }, propertyInfo.DeclaringType);
|
||||||
DynamicMethod dynamicMethod = CreateDynamicMethod("Set" + propertyInfo.Name, null, new[] { typeof(object), typeof(object) }, propertyInfo.DeclaringType);
|
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
|
GenerateCreateSetPropertyIL(propertyInfo, generator);
|
||||||
|
|
||||||
|
return (Action<T, object>)dynamicMethod.CreateDelegate(typeof(Action<T, object>));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void GenerateCreateSetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
|
||||||
|
{
|
||||||
|
MethodInfo setMethod = propertyInfo.GetSetMethod(true);
|
||||||
if (!setMethod.IsStatic)
|
if (!setMethod.IsStatic)
|
||||||
generator.PushInstance(propertyInfo.DeclaringType);
|
generator.PushInstance(propertyInfo.DeclaringType);
|
||||||
|
|
||||||
@@ -192,8 +221,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
generator.UnboxIfNeeded(propertyInfo.PropertyType);
|
generator.UnboxIfNeeded(propertyInfo.PropertyType);
|
||||||
generator.CallMethod(setMethod);
|
generator.CallMethod(setMethod);
|
||||||
generator.Return();
|
generator.Return();
|
||||||
|
|
||||||
return (Action<T, object>)dynamicMethod.CreateDelegate(typeof(Action<T, object>));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user