I have seen a number of similar posts and it seems as though the var1 I have declared seems to need to be passed in elsewhere, but I can't seem to figure it out.
public Expression<Func<ElementNode, bool>> CreateEqualNameExpression(string match)
{
var parm = Expression.Parameter(typeof(ElementNode), "element");
var expr = Expression.Call(parm, typeof(ElementNode).GetProperty("Name").GetGetMethod());
var var1 = Expression.Variable(typeof(string), "elementName");
var assign = Expression.Assign(var1, expr);
var parm2 = Expression.Constant(match, typeof(string));
var exp = Expression.Equal(assign, parm2);
return Expression.Lambda<Func<ElementNode, bool>>(exp, new[] { parm });
}
basically I'm trying to create a method that represents
(ElementNode ele) => ele.Name == match;
but I'm having a really hard time coming up with the solution. Any help would be greatly appreciated.
I'm getting the error: 'elementName' of type 'System.STring' referenced from scope'', but it is not defined.