-Fixed dynamic property getter type information

This commit is contained in:
James Newton-King
2016-05-01 17:23:48 +12:00
parent b71ca75905
commit e31200aead
2 changed files with 19 additions and 1 deletions
@@ -175,6 +175,24 @@ namespace Newtonsoft.Json.Tests.Utilities
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey)result;
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)
{
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();
GenerateCreateGetPropertyIL(propertyInfo, generator);