System.Reflection.MemberTypes在DNX 5.0中的位置是什么?

时间:2015-11-24 19:53:42

标签: c# reflection dnx

.net 4.5了。 DNXCore v5在哪里?

我的具体错误信息是: DNXCore,Version=v5.0 error CS0103: The name 'MemberTypes' does not exist in the current context.

在之前的.nets中,它是Enum上的System.Reflection,并且是obj.GetType().GetMember(memberName).MemberType(字段,属性等)的结果

修改

这就是我正在做的事情:

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;
                   ...

1 个答案:

答案 0 :(得分:3)

看起来(至少目前为止)this is the recommended way to achieve the same functionality.

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);