FastMember ObjectReader doesn't work with inherited interfaces

非 Y 不嫁゛ 提交于 2019-12-06 03:30:24

I cloned the Repository of the FastMember Package, in the TypeAccessor class I changed line 265 from:

PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

to:

PropertyInfo[] props = GetPrpsInterfaces(type, BindingFlags.Public | BindingFlags.Instance).ToArray();

The Implementation of the replacing function:

static IEnumerable<PropertyInfo> GetPrpsInterfaces(Type type, BindingFlags flags)
{
      if (!type.IsInterface)
           return type.GetProperties(flags);

      return (new Type[] { type }).Concat(type.GetInterfaces()).SelectMany(i => i.GetProperties(flags));
}

I found here: GetProperties() to return all properties for an interface inheritance hierarchy

This worked for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!