System.Waf.Applications.RecentFileList.Remove C# (CSharp) Метод

Remove() публичный Метод

Removes the specified recent file.
The argument recentFile must not be null. The argument recentFile was not found in the recent files list.
public Remove ( RecentFile recentFile ) : void
recentFile RecentFile The recent file to remove.
Результат void
        public void Remove(RecentFile recentFile)
        {
            if (recentFile == null) { throw new ArgumentNullException(nameof(recentFile)); }
            if (recentFiles.Remove(recentFile))
            {
                recentFile.PropertyChanged -= RecentFilePropertyChanged;
            }
            else
            {
                throw new ArgumentException("The passed recentFile was not found in the recent files list.", nameof(recentFile));
            }
        }

Usage Example

Пример #1
0
        public void Remove()
        {
            RecentFileList recentFileList = new RecentFileList();

            AssertHelper.ExpectedException<ArgumentNullException>(() => recentFileList.Remove(null));

            recentFileList.AddFile("Doc1");
            recentFileList.AddFile("Doc2");
            recentFileList.AddFile("Doc3");

            RecentFile lastAdded = recentFileList.RecentFiles.First();

            recentFileList.Remove(recentFileList.RecentFiles.Last());
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc2" }));
            recentFileList.Remove(recentFileList.RecentFiles.First());
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2" }));
            recentFileList.Remove(recentFileList.RecentFiles.First());
            Assert.IsTrue(!recentFileList.RecentFiles.Any());

            // Try to delete a RecentFile object which was already deleted.
            AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.Remove(lastAdded));
        }