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...
}
I don’t understand what you are doing, I think you could probably completely avoid some of the code you show here.
I wrote this “GetMemberName” extension method, you probably can do something with this code:
Edit:
just to sketch up a solution: