1: CLS
2:
3: . C:\SCHREIBTISCH\SVN\PSVP\DarthEnumerator\Darth-Enumerator.ps1
4: #. C:\SCHREIBTISCH\SVN\PSVP\DarthEnumerator\Lord-Enumerator.ps1
5:
6: Get-Help Get-Enumerator -Full
7:
8:
9: "Hashtable Tests"
10:
11: "----- 1"
12: $Team = @{4 = "Joe"; 2 = "Steve"; 12 = "Tom"}
13: $Team.GetType().Fullname
14:
15: "----- 2"
16: $Team | Sort-Object
17:
18: "----- 3"
19: $Team | Get-Enumerator
20:
21: "----- 4"
22: $Team.GetEnumerator() | Sort-Object -Property "Key"
23:
24: "----- 5"
25: $Team | Get-Enumerator | Sort-Object -Property "Key"
26:
27: "----- 6"
28: $Team |e| so Key
29:
30: "----- 7"
31: $Team | Get-Enumerator -Force | Sort-Object -Property "Key"
32:
33: "----- 8"
34: $Team |e -f| so Key
35:
36: "----- 9"
37: $Team | Get-Enumerator -Force -Strict | Sort-Object -Property "Key"
38:
39: "----- 10"
40: $Team |e -f -s| so Key
41:
42: "Array Tests"
43:
44: "===== 1"
45: $RosterNames = "Joe", "Steve", "Tom"
46: $RosterNumbers = 4,2,12
47: $RosterNames.GetType().Fullname
48: $RosterNumbers.GetType().Fullname
49:
50: "===== 2"
51: $RosterNumbers
52: $RosterNumbers |e -f| so
53:
54: "===== 3"
55: if ($true)
56: {
57: trap {"Expected Error: Pipeline input is not an IEnumerable - Actual Error: $_"; continue}
58: $RosterNumbers |e -f -s| so
59: }
60:
61: "===== 4"
62: if ($true)
63: {
64: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
65: $RosterNames |e| so
66: }
67:
68: "===== 5"
69: if ($true)
70: {
71: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
72: $RosterNumbers |e| so
73: }
74:
75: "===== 6"
76: $RosterNumbers | Get-Enumerator -Force | Sort-Object
77:
78: "===== 7"
79: $RosterNumbers | e -f | so # Interesting: Calling GetEnumerators on the string
80:
81: "===== 8"
82: $RosterNames
83: $RosterNames | Get-Enumerator -Force | Sort-Object
84:
85: "===== 9"
86: $RosterNames | e -f | so # Interesting: Calling GetEnumerators on the string
87:
88: "===== 10"
89: $RosterNames | e -Force -PreserveString| so
90:
91: "===== 11"
92: $RosterNames | e -Force -PreserveString -Strict| so
93:
94: "===== 12"
95: $RosterNames | e -f -p | so
96:
97: "===== 13"
98: $RosterNames | e -f -p -s| so
99:
100:
101: "ArrayList Tests"
102:
103: "..... 1"
104: $RosterNameList = New-Object -TypeName "System.Collections.ArrayList"
105: $RosterNames | foreach-object {$RosterNameList.Add($_)}| Out-Null
106: $RosterNameList
107: $RosterNameList.GetType().Fullname
108:
109: $RosterNumberList = New-Object -TypeName "System.Collections.ArrayList"
110: $RosterNumbers | foreach-object {$RosterNumberList.Add($_)} | Out-Null
111: $RosterNumberList
112: $RosterNumberList.GetType().Fullname
113:
114: "..... 2"
115: $RosterNumberList
116: $RosterNumberList |e -f| so
117:
118: "..... 3"
119: if ($true)
120: {
121: trap {"Expected Error: Pipeline input is not an IEnumerable - Actual Error: $_"; continue}
122: $RosterNumberList |e -f -s| so #ArrayList gets implicitly converted to an array (ToArray()) and treated as such
123: }
124:
125: "..... 4"
126: if ($true)
127: {
128: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
129: $RosterNumberList |e| so
130: }
131:
132: "..... 5"
133: if ($true)
134: {
135: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
136: $RosterNameList |e| so
137: }
138:
139: "..... 6"
140: $RosterNumberList | Get-Enumerator -Force | Sort-Object
141:
142: "..... 7"
143: $RosterNumberList | e -f | so
144:
145: "..... 8"
146: $RosterNameList
147: $RosterNameList | Get-Enumerator -Force | Sort-Object
148:
149: "..... 9"
150: $RosterNameList | e -f | so
151:
152: "..... 10"
153: $RosterNameList | e -Force -PreserveString| so
154:
155: "..... 11"
156: $RosterNameList | e -Force -PreserveString -Strict| so
157:
158: "..... 12"
159: $RosterNameList | e -f -p | so
160:
161: "..... 13"
162: $RosterNameList | e -f -p -s| so
163:
164:
165: "SortedList Tests" #Doesn't have ToArray() function
166:
167: "~~~~~ 1"
168: $RosterNameList = New-Object -TypeName "System.Collections.SortedList"
169: $RosterNames | foreach-object {$RosterNameList.Add($_, $_)}| Out-Null
170: $RosterNameList
171: $RosterNameList.GetType().Fullname
172:
173: $RosterNumberList = New-Object -TypeName "System.Collections.SortedList"
174: $RosterNumbers | foreach-object {$RosterNumberList.Add($_, $_)} | Out-Null
175: $RosterNumberList
176: $RosterNumberList.GetType().Fullname
177:
178: "~~~~~ 2"
179: $RosterNumberList
180: $RosterNumberList |e -f| %{$_.Value}
181:
182: "~~~~~ 3"
183: $RosterNumberList |e -f -s| %{$_.Value}
184:
185: "~~~~~ 4"
186: if ($true)
187: {
188: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
189: $RosterNumberList |e| %{$_.Value}
190: }
191:
192: "~~~~~ 5"
193: if ($true)
194: {
195: trap {"Expected Error: Pipeline input is not a HashTable - Actual Error: $_"; continue}
196: $RosterNameList |e| %{$_.Value}
197: }
198:
199: "~~~~~ 6"
200: $RosterNumberList | Get-Enumerator -Force | Sort-Object
201:
202: "~~~~~ 7"
203: $RosterNumberList | e -f | %{$_.Value}
204:
205: "~~~~~ 8"
206: $RosterNameList
207: $RosterNameList | Get-Enumerator -Force | Sort-Object
208:
209: "~~~~~ 9"
210: $RosterNameList | e -f | %{$_.Value}
211:
212: "~~~~~ 10"
213: $RosterNameList | e -f -s | %{$_.Value}
214:
215: "~~~~~ 11"
216: $RosterNameList | e -Force -PreserveString| %{$_.Value}
217:
218: "~~~~~ 12"
219: $RosterNameList | e -Force -PreserveString -Strict| %{$_.Value}
220:
221: "~~~~~ 13"
222: $RosterNameList | e -f -p | %{$_.Value}
223:
224: "~~~~~ 14"
225: $RosterNameList | e -f -p -s| %{$_.Value}
226: