You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across an issue where I can't seem to explain why Expression.Compile works while FEC gives me a different answer. It's a pretty simple comparison, checking if the time passed in equals the time specified on a class with a nullable value.
public class HasDateTime(DateTime? t)
{
public DateTime? T { get; } = t;
}
[Test]
public void DateTimeTest()
{
var time = DateTime.UtcNow;
var p = new ParameterExpression[1]; // the parameter expressions
var e = new Expression[3]; // the unique expressions
var exp = Expression.Lambda<Func<HasDateTime, bool>>(
e[0]=Expression.MakeBinary(ExpressionType.Equal,
e[1]=Expression.Property(
p[0]=Expression.Parameter(typeof(HasDateTime), nameof(HasDateTime)),
typeof(HasDateTime).GetProperty(nameof(HasDateTime.T))),
e[2]=Expression.Constant(time, typeof(System.DateTime?)),
liftToNull: false,
typeof(System.DateTime).GetMethods().Single(x => !x.IsGenericMethod && x.Name == "op_Equality" && x.GetParameters().Select(y => y.ParameterType).SequenceEqual(new[] { typeof(System.DateTime), typeof(System.DateTime) }))),
p[0 // (HasDateTime)
]);
Assert.IsTrue(exp.Compile()(new HasDateTime(time))); // passes, as expected.
Assert.IsTrue(exp.CompileFast()(new HasDateTime(time))); // this fails!
}
Thanks!
The text was updated successfully, but these errors were encountered:
Hello,
I came across an issue where I can't seem to explain why Expression.Compile works while FEC gives me a different answer. It's a pretty simple comparison, checking if the time passed in equals the time specified on a class with a nullable value.
Thanks!
The text was updated successfully, but these errors were encountered: