Mercurial > repos > IBBoard
annotate Collections/DictionaryToArrayConverter.cs @ 11:ba9239164de2
Fixes #5 - Converting dictionary to array
* Add genericed DictionaryToArrayConverter class to IBBoard utils
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Jan 2009 14:44:19 +0000 |
parents | |
children | 465b672e9682 |
rev | line source |
---|---|
11
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // DictionaryToArrayConverter.cs is a part of the IBBoard utils library (referred to from here as "this program") |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // Copyright (C) 2009 IBBoard |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 // |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 // This program is free software: you can redistribute it and/or modify |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 // it under the terms of the GNU Lesser General Public License as published by |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 // the Free Software Foundation, either version 3 of the License, or |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 // (at your option) any later version. |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 // |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 // This program is distributed in the hope that it will be useful, |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 // GNU Lesser General Public License for more details. |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 // |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 // You should have received a copy of the GNU Lesser General Public License |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 // |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 using System; |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 using System.Collections.Generic; |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 namespace IBBoard |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 { |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 public class DictionaryToArrayConverter |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 { |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 public static VALUE_TYPE[] Convert<KEY_TYPE, VALUE_TYPE>(Dictionary<KEY_TYPE, VALUE_TYPE> dictionary) |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 { |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 VALUE_TYPE[] col = (VALUE_TYPE[]) new object[dictionary.Count]; |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 dictionary.Values.CopyTo(col, 0); |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 return (VALUE_TYPE[])col; |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
ba9239164de2
Fixes #5 - Converting dictionary to array
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 } |