forked from shengqh/RCPA.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemInfo.cs
90 lines (77 loc) · 1.81 KB
/
ItemInfo.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace RCPA
{
public class ItemInfo
{
public ItemInfo()
{
SubItems = new List<string>();
Selected = false;
}
public List<string> SubItems { get; set; }
public bool Selected { get; set; }
}
public class ItemInfoList : List<ItemInfo>
{
public ItemInfoList() { }
public ItemInfoList(IEnumerable<ItemInfo> collection)
: base(collection)
{ }
public ItemInfoList(IEnumerable<string> collections)
{
AddRange(
from c in collections
select new ItemInfo()
{
Selected = false,
SubItems = new List<string>(new[] { c })
});
}
public string[] GetAllItems()
{
return (from item in this
select item.SubItems[0]).ToArray();
}
public string[] GetSelectedItems()
{
return (from item in this
where item.Selected
select item.SubItems[0]).ToArray();
}
private Dictionary<string, string> GetMap(Func<ItemInfo, bool> valid)
{
Dictionary<string, string> result = new Dictionary<string, string>();
foreach (var m in this)
{
if (valid(m))
{
if (m.SubItems.Count > 1)
{
result[m.SubItems[0]] = m.SubItems[1];
}
else
{
result[m.SubItems[0]] = string.Empty;
}
}
}
return result;
}
public Dictionary<string, string> GetAllItemMap()
{
return GetMap(m => true);
}
public Dictionary<string, string> GetSelectItemMap()
{
return GetMap(m => m.Selected);
}
}
public class SimpleItemInfos : IItemInfos
{
public ItemInfoList Items { get; set; }
}
}