diff --git a/Octokit.Tests/SimpleJsonSerializerTests.cs b/Octokit.Tests/SimpleJsonSerializerTests.cs index e8aa392d..0a69254c 100644 --- a/Octokit.Tests/SimpleJsonSerializerTests.cs +++ b/Octokit.Tests/SimpleJsonSerializerTests.cs @@ -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(json); + + Assert.Equal("commit-sha", result.Sha); + Assert.Equal("commit-url", result.Url); + Assert.Equal("commit-message", result.Message); + } } public class Sample diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index fdb57d48..7588a721 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -1723,12 +1723,41 @@ namespace Octokit public static IEnumerable 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(); + 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 Build(IEnumerable properties) + { + var propertyList = new List(); + foreach (var property in properties) + { + propertyList.Add(property); + } + return propertyList; + } + public static IEnumerable GetFields(Type type) { #if SIMPLE_JSON_TYPEINFO