I'm building SQL expressions from LINQ Expressions and liking it verry much. However an issue with refactoring has come up. Suppose I want to check the Method of a MethodCallExpression, I would do something like this:
MethodCallExpression expr = ... // An expression from somewhere...
if (expr.Method == typeof(SqlFilterExtensions).GetMethod("Like", BindingFlags.Static | BindingFlags.Public))
{
// Generate the SQL...
}
It works great, but if someone was to rename, move or somehow alter the method, this would fail silently.
I have come up with one idea, but I find it ugly as H...
if (expr.Method == new Func<string,string,bool>(SqlFilterExtensions.Like).Method)
{
// Generate the SQL...
}