提交 959b99e1 编写于 作者: S Sam Saffron

Paul Bartrum fix for inherited class deserialization

上级 aa601bff
......@@ -556,7 +556,12 @@ private static object GetStructDeserializer<T>(IDataReader reader)
var properties = typeof(T)
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Select(p => new { Name = p.Name, Setter = p.GetSetMethod(true), Type = p.PropertyType })
.Select(p => new
{
Name = p.Name,
Setter = p.DeclaringType == typeof(T) ? p.GetSetMethod(true) : p.DeclaringType.GetProperty(p.Name).GetSetMethod(true),
Type = p.PropertyType
})
.Where(info => info.Setter != null)
.ToList();
......
......@@ -317,5 +317,27 @@ public void TestMultiMapDynamic()
connection.Execute("drop table #Users drop table #Posts");
}
class InheritanceTest1
{
public string Base1 { get; set; }
public string Base2 { get; private set; }
}
class InheritanceTest2 : InheritanceTest1
{
public string Derived1 { get; set; }
public string Derived2 { get; private set; }
}
public void TestInheritance()
{
// Test that inheritance works.
var list = connection.Query<InheritanceTest2>("select 'One' as Derived1, 'Two' as Derived2, 'Three' as Base1, 'Four' as Base2");
list.First().Derived1.IsEqualTo("One");
list.First().Derived2.IsEqualTo("Two");
list.First().Base1.IsEqualTo("Three");
list.First().Base2.IsEqualTo("Four");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册