You can try to make the expression completely manually, which will give you the opportunity to specify the name of the property as a string. This is not a complete solution and it has not been tested, but it can give you a starting point to understand what I mean:
var parameter = Expression.Parameter(typeof(Message), "o"); var getname = Expression.Property(parameter, "Body"); var isnullorempty = Expression.Not(Expression.Call(typeof(string), "IsNullOrEmpty", null, getname)); var compare = Expression.Equal(getname, Expression.Constant("thisvalue")); var combined = Expression.And(isnullorempty, compare); var lambda = Expression.Lambda(combined, parameter);
So, you would change your function to take Body as a parameter, and then drop the lambda at the end:
expression<func<Message, bool>>
Maybe I don't have the syntax to create lambda for sure.
source share