开发者

Placeholder in C# expression WPF

Is it possible to use placeholders in C# expression? I have a expression for filtering records in a datagrid as follows:

    view.Filter = item =>
        {                
            OrdsRlsd vitem = item as OrdsRlsd;                

            if (vitem.OrderNo >= Convert.ToInt32(TxtCond1.Text) &&a开发者_开发问答mp; vitem.OrderNo <= Convert.ToInt32(TxtCond2.Text))
            {
                return true;
            }
            return false;
        };  

In this expression, the the comparison operators and the TxtCond1 and TxtCond2 values are dynamic. Can we use a placeholder for that?


Yes you can pass those as Func<string> parameters. So say your function definition is like this

public void Filter(Func<string> string1, Func<string> string2)
{
var result = item =>
        {                
            OrdsRlsd vitem = item as OrdsRlsd;                

            if (vitem.OrderNo >= Convert.ToInt32(string1.Invoke()) && vitem.OrderNo <= Convert.ToInt32(string2.Invoke()))
            {
                return true;
            }
            return false;
        };  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜