mattwar / iqtoolkit

A Toolkit for building LINQ IQueryable providers. This is the official move of my IQToolkit project from CodePlex.
Other
237 stars 77 forks source link

compare property expression of inherited class #28

Open samuelpsfung opened 3 years ago

samuelpsfung commented 3 years ago
public class BaseClass
{
    public int ID { get; set; }
}

public class SubClass : BaseClass
{ }

var param = Expression.Parameter(typeof(SubClass));
var body = Expression.Property(param, "ID");
var lambda = Expression.Lambda<Func<SubClass, int>>(body, param);

Expression<Func<SubClass, int>> lambdaExpr = x => x.ID;
Console.WriteLine(ExpressionComparer.AreEqual(lambda, lambdaExpr));

These 2 lambdas should be equal, but ExpressionComparer.AreEqual() returns false.

This issue should be related to this question: https://stackoverflow.com/questions/13615927/equality-for-net-propertyinfos#13616025