Allow deserializing of base properties in SIMPE_JSON_TYPEINFO mode (works otherwise)

This commit is contained in:
John Nye
2013-11-07 22:38:33 +00:00
committed by Haacked
parent c62712eb82
commit d433eec548
2 changed files with 42 additions and 1 deletions
@@ -79,6 +79,18 @@ namespace Octokit.Tests
Assert.True(sample.IsSomething);
Assert.True(sample.Private);
}
[Fact]
public void DeserializesInheritedProperties()
{
const string json = "{\"sha\":\"commit-sha\",\"url\":\"commit-url\",\"message\":\"commit-message\"}";
var result = new SimpleJsonSerializer().Deserialize<Commit>(json);
Assert.Equal("commit-sha", result.Sha);
Assert.Equal("commit-url", result.Url);
Assert.Equal("commit-message", result.Message);
}
}
public class Sample
+30 -1
View File
@@ -1723,12 +1723,41 @@ namespace Octokit
public static IEnumerable<PropertyInfo> GetProperties(Type type)
{
#if SIMPLE_JSON_TYPEINFO
return type.GetTypeInfo().DeclaredProperties;
var typeInfo = type.GetTypeInfo();
var properties = typeInfo.DeclaredProperties;
if(typeInfo.BaseType == null)
{
return properties;
}
var result = new List<PropertyInfo>();
foreach (var property in properties)
{
result.Add(property);
}
var baseProperties = GetProperties(typeInfo.BaseType);
foreach (var property in baseProperties)
{
result.Add(property);
}
return result;
#else
return type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
#endif
}
public static IList<PropertyInfo> Build(IEnumerable<PropertyInfo> properties)
{
var propertyList = new List<PropertyInfo>();
foreach (var property in properties)
{
propertyList.Add(property);
}
return propertyList;
}
public static IEnumerable<FieldInfo> GetFields(Type type)
{
#if SIMPLE_JSON_TYPEINFO