在DNX 5.0中,System.Reflection.MemberTypes去哪了?

3
.NET 4.5中有,但在DNXCore v5中呢?
我的具体错误信息是:
DNXCore,Version=v5.0 error CS0103: The name 'MemberTypes' does not exist in the current context.
在以前的.NET版本中,它是System.Reflection上的一个枚举,并且会成为obj.GetType().GetMember(memberName).MemberType(Field、Property等)的结果。
编辑:
这是我正在做的事情:
using System.Linq;
using System.Reflection;

    internal static object Send(object obj, string callableName, object[] parameters = null)
    {
        var info = InfoFor(obj, callableName);
        return ValueFor(obj, info);
    }

InfoFor 返回 MethodInfoPropertyInfo 或任何与 callableName 匹配的内容。

下面是 ValueFor(其中试图使用 MemberTypes

  private static object ValueFor(object obj, dynamic member)
        {
            object value = null;

            if (member != null)
            {
                switch ((System.Reflection.MemberTypes)member.MemberType)
                {
                    case MemberTypes.Field:
                        value = ((FieldInfo)member).GetValue(obj);
                        break;
                    case MemberTypes.Property:
                        value = ((PropertyInfo)member).GetValue(obj, null);
                        break;
                   ...

发布你的代码,这样别人才能推荐一个可行的替代方案。 - Hans Passant
在 http://github.com/dotnet/corefx 上进行代码搜索,并检查其是否存在。 - Lex Li
我认为这实际上是一个 bug:https://github.com/dotnet/corefx/issues/4670 - NullVoxPopuli
1个回答

3
看起来(至少目前)这是实现相同功能的推荐方法。
FieldInfo field = member as FieldInfo;
if (field != null)
   return field.GetValue(obj);
PropertyInfo property member as PropertyInfo;
if (property != null)
   return property.GetValue(obj, null);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接