.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
返回MethodInfo
,PropertyInfo
或其他匹配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;
...
答案 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);