суббота, 27 февраля 2010 г.

EqualityComparer for C# 3.0 Expressions

.NET Expression classes let us perform only reference equality checks on them. But sometimes we need to check the true value equality.  As part of my attempt to build autocacher for LINQ TO SQL compiled queries I created an equality comparer that implements IEqualityComparer<Expression> interface. It lets me, for example, to use an Expression as a key in a dictionary. The implementation is .NET 3.5 specific  and based on the example ExpressionVisitor class from MSDN. As a bonus  there are extensions to the Expression class in the project so that you can visit and rewrite  expressions without deriving from ExpressionVisitor. It can be very handy in simple scenarios.

ExpressionEqualityComparer.zip

p.s. BTW in .NET 4.0 they made  the ExpressionVistor class public.  In .NET 3.5 it  was internal.

Комментариев нет:

Отправить комментарий