-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathUsbDiskCollection.cs
58 lines (47 loc) · 1.45 KB
/
UsbDiskCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//************************************************************************************************
// Copyright © 2010 Steven M. Cohn. All Rights Reserved.
//
//************************************************************************************************
namespace iTuner
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
/// <summary>
/// Maintains a collection of USB disk objects.
/// </summary>
public class UsbDiskCollection : ObservableCollection<UsbDisk>
{
/// <summary>
/// Determines if the named disk is contained in this collection.
/// </summary>
/// <param name="name">The Windows name, or drive letter, of the disk to remove.</param>
/// <returns>
/// <b>True</b> if the item is found; otherwise <b>false</b>.
/// </returns>
public bool Contains (string name)
{
return this.AsQueryable<UsbDisk>().Any(d => d.Name == name) == true;
}
/// <summary>
/// Remove the named disk from the collection.
/// </summary>
/// <param name="name">The Windows name, or drive letter, of the disk to remove.</param>
/// <returns>
/// <b>True</b> if the item is removed; otherwise <b>false</b>.
/// </returns>
public bool Remove (string name)
{
UsbDisk disk =
(this.AsQueryable<UsbDisk>()
.Where(d => d.Name == name)
.Select(d => d)).FirstOrDefault<UsbDisk>();
if (disk != null)
{
return this.Remove(disk);
}
return false;
}
}
}