mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Add support for deserializing non-public members
But only ones with ParameterAttribute applied.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user