我正在尝试DateTime
通过反射检索一个。该值不在类或静态类中,而是来自lambda expression
...
我有这个非常简单的 lambda 表达式:ATest => ATest.MyDate == DateTime.Now
现在,通过ExpressionVisitor
我正在尝试获取日期时间值:
public class ExpressionComparionsVisitor : ExpressionVisitor
{
public Expression Modify(Expression expression)
{
return base.Visit(expression);
}
protected override Expression VisitMember(MemberExpression node)
{
if (node.NodeType == ExpressionType.MemberAccess)
{
if (node.Member.MemberType == System.Reflection.MemberTypes.Field)
{
if (node.Type == typeof(DateTime))
{
System.Reflection.FieldInfo fieldInfo = node.Member as System.Reflection.FieldInfo;
if (fieldInfo != null)
{
//Here what I have tried, but no success
//var n = (DateTime)fieldInfo.GetValue(fieldInfo);
//var n = (DateTime)fieldInfo.GetValue(typeof(DateTime));
//var n = (DateTime)fieldInfo.GetValue(node.Member);
//var n = (DateTime)fieldInfo.GetValue(null);
}
}
}
}
return base.VisitMember(node);
}
}
如何获取该字段的 DateTime 值?谢谢