1 |
william |
92 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using System.Security; |
6 |
|
|
using System.Runtime.Serialization; |
7 |
|
|
using System.Runtime.CompilerServices; |
8 |
|
|
|
9 |
|
|
namespace libxmltv.Core |
10 |
|
|
{ |
11 |
|
|
internal static class ThrowHelper |
12 |
|
|
{ |
13 |
|
|
// Methods |
14 |
|
|
internal static string GetArgumentName(ExceptionArgument argument) |
15 |
|
|
{ |
16 |
|
|
switch (argument) |
17 |
|
|
{ |
18 |
|
|
case ExceptionArgument.obj: |
19 |
|
|
return "obj"; |
20 |
|
|
|
21 |
|
|
case ExceptionArgument.dictionary: |
22 |
|
|
return "dictionary"; |
23 |
|
|
|
24 |
|
|
case ExceptionArgument.dictionaryCreationThreshold: |
25 |
|
|
return "dictionaryCreationThreshold"; |
26 |
|
|
|
27 |
|
|
case ExceptionArgument.array: |
28 |
|
|
return "array"; |
29 |
|
|
|
30 |
|
|
case ExceptionArgument.info: |
31 |
|
|
return "info"; |
32 |
|
|
|
33 |
|
|
case ExceptionArgument.key: |
34 |
|
|
return "key"; |
35 |
|
|
|
36 |
|
|
case ExceptionArgument.collection: |
37 |
|
|
return "collection"; |
38 |
|
|
|
39 |
|
|
case ExceptionArgument.list: |
40 |
|
|
return "list"; |
41 |
|
|
|
42 |
|
|
case ExceptionArgument.match: |
43 |
|
|
return "match"; |
44 |
|
|
|
45 |
|
|
case ExceptionArgument.converter: |
46 |
|
|
return "converter"; |
47 |
|
|
|
48 |
|
|
case ExceptionArgument.queue: |
49 |
|
|
return "queue"; |
50 |
|
|
|
51 |
|
|
case ExceptionArgument.stack: |
52 |
|
|
return "stack"; |
53 |
|
|
|
54 |
|
|
case ExceptionArgument.capacity: |
55 |
|
|
return "capacity"; |
56 |
|
|
|
57 |
|
|
case ExceptionArgument.index: |
58 |
|
|
return "index"; |
59 |
|
|
|
60 |
|
|
case ExceptionArgument.startIndex: |
61 |
|
|
return "startIndex"; |
62 |
|
|
|
63 |
|
|
case ExceptionArgument.value: |
64 |
|
|
return "value"; |
65 |
|
|
|
66 |
|
|
case ExceptionArgument.count: |
67 |
|
|
return "count"; |
68 |
|
|
|
69 |
|
|
case ExceptionArgument.arrayIndex: |
70 |
|
|
return "arrayIndex"; |
71 |
|
|
|
72 |
|
|
case ExceptionArgument.name: |
73 |
|
|
return "name"; |
74 |
|
|
|
75 |
|
|
case ExceptionArgument.mode: |
76 |
|
|
return "mode"; |
77 |
|
|
} |
78 |
|
|
return string.Empty; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
internal static string GetResourceName(ExceptionResource resource) |
82 |
|
|
{ |
83 |
|
|
switch (resource) |
84 |
|
|
{ |
85 |
|
|
case ExceptionResource.Argument_ImplementIComparable: |
86 |
|
|
return "Argument_ImplementIComparable"; |
87 |
|
|
|
88 |
|
|
case ExceptionResource.Argument_InvalidType: |
89 |
|
|
return "Argument_InvalidType"; |
90 |
|
|
|
91 |
|
|
case ExceptionResource.Argument_InvalidArgumentForComparison: |
92 |
|
|
return "Argument_InvalidArgumentForComparison"; |
93 |
|
|
|
94 |
|
|
case ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck: |
95 |
|
|
return "Argument_InvalidRegistryKeyPermissionCheck"; |
96 |
|
|
|
97 |
|
|
case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum: |
98 |
|
|
return "ArgumentOutOfRange_NeedNonNegNum"; |
99 |
|
|
|
100 |
|
|
case ExceptionResource.Arg_ArrayPlusOffTooSmall: |
101 |
|
|
return "Arg_ArrayPlusOffTooSmall"; |
102 |
|
|
|
103 |
|
|
case ExceptionResource.Arg_NonZeroLowerBound: |
104 |
|
|
return "Arg_NonZeroLowerBound"; |
105 |
|
|
|
106 |
|
|
case ExceptionResource.Arg_RankMultiDimNotSupported: |
107 |
|
|
return "Arg_RankMultiDimNotSupported"; |
108 |
|
|
|
109 |
|
|
case ExceptionResource.Arg_RegKeyDelHive: |
110 |
|
|
return "Arg_RegKeyDelHive"; |
111 |
|
|
|
112 |
|
|
case ExceptionResource.Arg_RegKeyStrLenBug: |
113 |
|
|
return "Arg_RegKeyStrLenBug"; |
114 |
|
|
|
115 |
|
|
case ExceptionResource.Arg_RegSetStrArrNull: |
116 |
|
|
return "Arg_RegSetStrArrNull"; |
117 |
|
|
|
118 |
|
|
case ExceptionResource.Arg_RegSetMismatchedKind: |
119 |
|
|
return "Arg_RegSetMismatchedKind"; |
120 |
|
|
|
121 |
|
|
case ExceptionResource.Arg_RegSubKeyAbsent: |
122 |
|
|
return "Arg_RegSubKeyAbsent"; |
123 |
|
|
|
124 |
|
|
case ExceptionResource.Arg_RegSubKeyValueAbsent: |
125 |
|
|
return "Arg_RegSubKeyValueAbsent"; |
126 |
|
|
|
127 |
|
|
case ExceptionResource.Argument_AddingDuplicate: |
128 |
|
|
return "Argument_AddingDuplicate"; |
129 |
|
|
|
130 |
|
|
case ExceptionResource.Serialization_InvalidOnDeser: |
131 |
|
|
return "Serialization_InvalidOnDeser"; |
132 |
|
|
|
133 |
|
|
case ExceptionResource.Serialization_MissingKeyValuePairs: |
134 |
|
|
return "Serialization_MissingKeyValuePairs"; |
135 |
|
|
|
136 |
|
|
case ExceptionResource.Serialization_NullKey: |
137 |
|
|
return "Serialization_NullKey"; |
138 |
|
|
|
139 |
|
|
case ExceptionResource.Argument_InvalidArrayType: |
140 |
|
|
return "Argument_InvalidArrayType"; |
141 |
|
|
|
142 |
|
|
case ExceptionResource.NotSupported_KeyCollectionSet: |
143 |
|
|
return "NotSupported_KeyCollectionSet"; |
144 |
|
|
|
145 |
|
|
case ExceptionResource.NotSupported_ValueCollectionSet: |
146 |
|
|
return "NotSupported_ValueCollectionSet"; |
147 |
|
|
|
148 |
|
|
case ExceptionResource.ArgumentOutOfRange_SmallCapacity: |
149 |
|
|
return "ArgumentOutOfRange_SmallCapacity"; |
150 |
|
|
|
151 |
|
|
case ExceptionResource.ArgumentOutOfRange_Index: |
152 |
|
|
return "ArgumentOutOfRange_Index"; |
153 |
|
|
|
154 |
|
|
case ExceptionResource.Argument_InvalidOffLen: |
155 |
|
|
return "Argument_InvalidOffLen"; |
156 |
|
|
|
157 |
|
|
case ExceptionResource.Argument_ItemNotExist: |
158 |
|
|
return "Argument_ItemNotExist"; |
159 |
|
|
|
160 |
|
|
case ExceptionResource.ArgumentOutOfRange_Count: |
161 |
|
|
return "ArgumentOutOfRange_Count"; |
162 |
|
|
|
163 |
|
|
case ExceptionResource.ArgumentOutOfRange_InvalidThreshold: |
164 |
|
|
return "ArgumentOutOfRange_InvalidThreshold"; |
165 |
|
|
|
166 |
|
|
case ExceptionResource.ArgumentOutOfRange_ListInsert: |
167 |
|
|
return "ArgumentOutOfRange_ListInsert"; |
168 |
|
|
|
169 |
|
|
case ExceptionResource.NotSupported_ReadOnlyCollection: |
170 |
|
|
return "NotSupported_ReadOnlyCollection"; |
171 |
|
|
|
172 |
|
|
case ExceptionResource.InvalidOperation_CannotRemoveFromStackOrQueue: |
173 |
|
|
return "InvalidOperation_CannotRemoveFromStackOrQueue"; |
174 |
|
|
|
175 |
|
|
case ExceptionResource.InvalidOperation_EmptyQueue: |
176 |
|
|
return "InvalidOperation_EmptyQueue"; |
177 |
|
|
|
178 |
|
|
case ExceptionResource.InvalidOperation_EnumOpCantHappen: |
179 |
|
|
return "InvalidOperation_EnumOpCantHappen"; |
180 |
|
|
|
181 |
|
|
case ExceptionResource.InvalidOperation_EnumFailedVersion: |
182 |
|
|
return "InvalidOperation_EnumFailedVersion"; |
183 |
|
|
|
184 |
|
|
case ExceptionResource.InvalidOperation_EmptyStack: |
185 |
|
|
return "InvalidOperation_EmptyStack"; |
186 |
|
|
|
187 |
|
|
case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection: |
188 |
|
|
return "ArgumentOutOfRange_BiggerThanCollection"; |
189 |
|
|
|
190 |
|
|
case ExceptionResource.InvalidOperation_EnumNotStarted: |
191 |
|
|
return "InvalidOperation_EnumNotStarted"; |
192 |
|
|
|
193 |
|
|
case ExceptionResource.InvalidOperation_EnumEnded: |
194 |
|
|
return "InvalidOperation_EnumEnded"; |
195 |
|
|
|
196 |
|
|
case ExceptionResource.NotSupported_SortedListNestedWrite: |
197 |
|
|
return "NotSupported_SortedListNestedWrite"; |
198 |
|
|
|
199 |
|
|
case ExceptionResource.InvalidOperation_NoValue: |
200 |
|
|
return "InvalidOperation_NoValue"; |
201 |
|
|
|
202 |
|
|
case ExceptionResource.InvalidOperation_RegRemoveSubKey: |
203 |
|
|
return "InvalidOperation_RegRemoveSubKey"; |
204 |
|
|
|
205 |
|
|
case ExceptionResource.Security_RegistryPermission: |
206 |
|
|
return "Security_RegistryPermission"; |
207 |
|
|
|
208 |
|
|
case ExceptionResource.UnauthorizedAccess_RegistryNoWrite: |
209 |
|
|
return "UnauthorizedAccess_RegistryNoWrite"; |
210 |
|
|
|
211 |
|
|
case ExceptionResource.ObjectDisposed_RegKeyClosed: |
212 |
|
|
return "ObjectDisposed_RegKeyClosed"; |
213 |
|
|
|
214 |
|
|
case ExceptionResource.NotSupported_InComparableType: |
215 |
|
|
return "NotSupported_InComparableType"; |
216 |
|
|
} |
217 |
|
|
return string.Empty; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
internal static void ThrowArgumentException(ExceptionResource resource) |
221 |
|
|
{ |
222 |
|
|
throw new ArgumentException(Environment.GetResourceString(GetResourceName(resource))); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument) |
226 |
|
|
{ |
227 |
|
|
throw new ArgumentException(Environment.GetResourceString(GetResourceName(resource)), GetArgumentName(argument)); |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
internal static void ThrowArgumentNullException(ExceptionArgument argument) |
231 |
|
|
{ |
232 |
|
|
throw new ArgumentNullException(GetArgumentName(argument)); |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
[MethodImpl(MethodImplOptions.NoInlining)] |
236 |
|
|
internal static void ThrowArgumentOutOfRangeException() |
237 |
|
|
{ |
238 |
|
|
ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) |
242 |
|
|
{ |
243 |
|
|
throw new ArgumentOutOfRangeException(GetArgumentName(argument)); |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) |
247 |
|
|
{ |
248 |
|
|
throw new ArgumentOutOfRangeException(GetArgumentName(argument), Environment.GetResourceString(GetResourceName(resource))); |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
internal static void ThrowInvalidOperationException(ExceptionResource resource) |
252 |
|
|
{ |
253 |
|
|
throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource))); |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
internal static void ThrowKeyNotFoundException() |
257 |
|
|
{ |
258 |
|
|
throw new KeyNotFoundException(); |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
internal static void ThrowNotSupportedException(ExceptionResource resource) |
262 |
|
|
{ |
263 |
|
|
throw new NotSupportedException(Environment.GetResourceString(GetResourceName(resource))); |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
internal static void ThrowObjectDisposedException(string objectName, ExceptionResource resource) |
267 |
|
|
{ |
268 |
|
|
throw new ObjectDisposedException(objectName, Environment.GetResourceString(GetResourceName(resource))); |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
internal static void ThrowSecurityException(ExceptionResource resource) |
272 |
|
|
{ |
273 |
|
|
throw new SecurityException(Environment.GetResourceString(GetResourceName(resource))); |
274 |
|
|
} |
275 |
|
|
|
276 |
|
|
internal static void ThrowSerializationException(ExceptionResource resource) |
277 |
|
|
{ |
278 |
|
|
throw new SerializationException(Environment.GetResourceString(GetResourceName(resource))); |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
internal static void ThrowUnauthorizedAccessException(ExceptionResource resource) |
282 |
|
|
{ |
283 |
|
|
throw new UnauthorizedAccessException(Environment.GetResourceString(GetResourceName(resource))); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
internal static void ThrowWrongKeyTypeArgumentException(object key, Type targetType) |
287 |
|
|
{ |
288 |
|
|
throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", new object[] { key, targetType }), "key"); |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
internal static void ThrowWrongValueTypeArgumentException(object value, Type targetType) |
292 |
|
|
{ |
293 |
|
|
throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", new object[] { value, targetType }), "value"); |
294 |
|
|
} |
295 |
|
|
} |
296 |
|
|
} |