lambda

来源:互联网 发布:非诚勿扰程序员专场 编辑:程序博客网 时间:2024/06/07 14:28
 public RelayCommand<TextEditor> SaveCommand
        {
            get
            {
?? 代表这个返回的_saveCommand为false时,就new一个新对象返回。
                return _saveCommand
                    ?? (_saveCommand = new RelayCommand<TextEditor>(
                    editor =>
                    {
                        try
                        {
                            // Can't add Encoding when save, it's wired, but it's the fact. Otherwise some wired character will appear at the beginning of line 1
                            File.WriteAllText(Case.CasePath, editor.Text);
                        }
                        catch (System.Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return;
                        }
                        MessageBox.Show("Case " + Case.CaseName + " saved.");
                    }, (x) => !this.CaseIsRunning));
            }
        }
editor => 和(x) =>这两个lambda函数作为参数在RelayCommand的构造函数中。
如_saveCommand=new RelayCommand<TextEditor>(void A{},bool B{});当B为真时,A函数才执行。
原创粉丝点击