mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Allow deserializing of base properties in SIMPE_JSON_TYPEINFO mode (works otherwise)
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user