-Fixed dynamic property getter type information
This commit is contained in:
@@ -175,6 +175,24 @@ 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 CreatePropertyGetter()
|
||||||
|
{
|
||||||
|
PropertyInfo namePropertyInfo = typeof(Person).GetProperty(nameof(Person.Name));
|
||||||
|
|
||||||
|
Assert.IsNotNull(namePropertyInfo);
|
||||||
|
|
||||||
|
var call = DynamicReflectionDelegateFactory.Instance.CreateGet<Person>(namePropertyInfo);
|
||||||
|
|
||||||
|
Person p = new Person();
|
||||||
|
p.Name = "Name!";
|
||||||
|
|
||||||
|
object result = call(p);
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
|
||||||
|
Assert.AreEqual("Name!", (string)result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
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);
|
DynamicMethod dynamicMethod = CreateDynamicMethod("Get" + propertyInfo.Name, typeof(object), new[] { typeof(T) }, propertyInfo.DeclaringType);
|
||||||
ILGenerator generator = dynamicMethod.GetILGenerator();
|
ILGenerator generator = dynamicMethod.GetILGenerator();
|
||||||
|
|
||||||
GenerateCreateGetPropertyIL(propertyInfo, generator);
|
GenerateCreateGetPropertyIL(propertyInfo, generator);
|
||||||
|
|||||||
Reference in New Issue
Block a user