2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Common / CharsetCollection.cs
1 /*
2  *  Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *     The contents of this file are subject to the Initial 
5  *     Developer's Public License Version 1.0 (the "License"); 
6  *     you may not use this file except in compliance with the 
7  *     License. You may obtain a copy of the License at 
8  *     http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *     Software distributed under the License is distributed on 
11  *     an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *     express or implied.  See the License for the specific 
13  *     language governing rights and limitations under the License.
14  * 
15  *  Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16  *  All Rights Reserved.
17  */
18
19 using System;
20 using System.Text;
21 using System.Collections;
22
23 namespace FirebirdSql.Data.Common
24 {
25         internal sealed class CharsetCollection : CollectionBase
26         {
27                 #region Indexers
28
29                 public Charset this[int index]
30                 {
31                         get { return (Charset)this.List[index]; }
32                 }
33
34                 public Charset this[string name]
35                 {
36                         get { return (Charset)this[this.IndexOf(name)]; }
37                 }
38
39                 #endregion
40
41                 #region Methods
42
43                 public int IndexOf(int id)
44                 {
45                         int index = 0;
46
47                         foreach (Charset item in this)
48                         {
49                                 if (item.ID == id)
50                                 {
51                                         return index;
52                                 }
53                                 index++;
54                         }
55
56                         return -1;
57                 }
58
59                 public int IndexOf(string name)
60                 {
61                         int index = 0;
62
63                         foreach (Charset item in this)
64                         {
65                                 if (GlobalizationHelper.CultureAwareCompare(item.Name, name))
66                                 {
67                                         return index;
68                                 }
69                                 index++;
70                         }
71
72                         return -1;
73                 }
74
75                 internal Charset Add(
76                         int             id,
77                         string  charset,
78                         int             bytesPerCharacter,
79                         string  systemCharset)
80                 {
81                         Charset charSet = new Charset(
82                                 id,
83                                 charset,
84                                 bytesPerCharacter,
85                                 systemCharset);
86
87                         return this.Add(charSet);
88                 }
89
90                 internal Charset Add(Charset charset)
91                 {
92                         this.List.Add(charset);
93
94                         return charset;
95                 }
96
97                 #endregion
98         }
99 }