Add support for deserializing non-public members

But only ones with ParameterAttribute applied.
This commit is contained in:
Haacked
2014-12-30 10:10:32 -08:00
parent fdd9073e43
commit 543d1bb863
6 changed files with 93 additions and 37 deletions
+15 -1
View File
@@ -2,17 +2,31 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Octokit.Internal;
using Octokit.Reflection;
namespace Octokit
{
internal static class ReflectionExtensions
{
public static string GetJsonFieldName(this MemberInfo memberInfo)
{
var memberName = memberInfo.Name;
var paramAttr = memberInfo.GetCustomAttribute<ParameterAttribute>();
if (paramAttr != null && !string.IsNullOrEmpty(paramAttr.Key))
{
memberName = paramAttr.Key;
}
return memberName.ToRubyCase();
}
public static IEnumerable<PropertyOrField> GetPropertiesAndFields(this Type type)
{
return ReflectionUtils.GetProperties(type).Select(property => new PropertyOrField(property))
.Union(ReflectionUtils.GetFields(type).Select(field => new PropertyOrField(field)))
.Where(p => p.IsPublic && !p.IsStatic);
.Where(p => (p.IsPublic || p.HasParameterAttribute) && !p.IsStatic);
}
public static bool IsDateTimeOffset(this Type type)