Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 370   Methods: 4
NCLOC: 155 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Utilities\TypesResolver\TypeAliasResolver.cs 75.0 % 85.5 % 75.0 % 84.4 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   #region Imports
28   using System;
29   using System.Collections;
30   using System.Collections.Specialized;
31  
32   using IBatisNet.Common.Exceptions;
33   #endregion
34  
35   namespace IBatisNet.Common.Utilities.TypesResolver
36   {
37   /// <summary>
38   /// Provides (and resolves) alias' for the common types.
39   /// </summary>
40   /// <remarks>
41   /// <p>
42   /// It's really just syntactic sugar so that a type definition
43   /// (in, say, a config file) can use 'int' instead of 'System.Int32'.
44   /// </p>
45   /// </remarks>
46   public class TypeAliasResolver
47   {
48   #region Constants
49  
50   /// <summary>
51   /// The alias around the 'list' type.
52   /// </summary>
53   public const string ArrayListAlias1 = "arraylist";
54   /// <summary>
55   /// An other alias around the 'list' type.
56   /// </summary>
57   public const string ArrayListAlias2 = "list";
58  
59   /// <summary>
60   /// The alias around the 'bool' type.
61   /// </summary>
62   public const string BoolAlias1 = "boolean";
63   /// <summary>
64   /// An other alias around the 'bool' type.
65   /// </summary>
66   public const string BoolAlias2 = "bool";
67  
68   /// <summary>
69   /// The alias around the 'byte' type.
70   /// </summary>
71   public const string ByteAlias = "byte";
72  
73   /// <summary>
74   /// The alias around the 'char' type.
75   /// </summary>
76   public const string CharAlias = "char";
77  
78   /// <summary>
79   /// The alias around the 'DateTime' type.
80   /// </summary>
81   public const string DateAlias1 = "datetime";
82   /// <summary>
83   /// An other alias around the 'DateTime' type.
84   /// </summary>
85   public const string DateAlias2 = "date";
86  
87   /// <summary>
88   /// The alias around the 'decimal' type.
89   /// </summary>
90   public const string DecimalAlias = "decimal";
91  
92   /// <summary>
93   /// The alias around the 'double' type.
94   /// </summary>
95   public const string DoubleAlias = "double";
96  
97   /// <summary>
98   /// The alias around the 'float' type.
99   /// </summary>
100   public const string FloatAlias1 = "float";
101   /// <summary>
102   /// An other alias around the 'float' type.
103   /// </summary>
104   public const string FloatAlias2 = "single";
105  
106   /// <summary>
107   /// The alias around the 'guid' type.
108   /// </summary>
109   public const string GuidAlias = "guid";
110  
111   /// <summary>
112   /// The alias around the 'Hashtable' type.
113   /// </summary>
114   public const string HashtableAlias1 = "hashtable";
115   /// <summary>
116   /// An other alias around the 'Hashtable' type.
117   /// </summary>
118   public const string HashtableAlias2 = "map";
119   /// <summary>
120   /// An other alias around the 'Hashtable' type.
121   /// </summary>
122   public const string HashtableAlias3 = "hashmap";
123  
124   /// <summary>
125   /// The alias around the 'short' type.
126   /// </summary>
127   public const string Int16Alias1 = "int16";
128   /// <summary>
129   /// An other alias around the 'short' type.
130   /// </summary>
131   public const string Int16Alias2 = "short";
132  
133   /// <summary>
134   /// The alias around the 'int' type.
135   /// </summary>
136   public const string Int32Alias1 = "Int32";
137   /// <summary>
138   /// An other alias around the 'int' type.
139   /// </summary>
140   public const string Int32Alias2 = "int";
141   /// <summary>
142   /// An other alias around the 'int' type.
143   /// </summary>
144   public const string Int32Alias3 = "integer";
145  
146   /// <summary>
147   /// The alias around the 'long' type.
148   /// </summary>
149   public const string Int64Alias1 = "int64";
150   /// <summary>
151   /// An other alias around the 'long' type.
152   /// </summary>
153   public const string Int64Alias2 = "long";
154  
155   /// <summary>
156   /// The alias around the 'unsigned short' type.
157   /// </summary>
158   public const string UInt16Alias1 = "uint16";
159   /// <summary>
160   /// An other alias around the 'unsigned short' type.
161   /// </summary>
162   public const string UInt16Alias2 = "ushort";
163  
164   /// <summary>
165   /// The alias around the 'unsigned int' type.
166   /// </summary>
167   public const string UInt32Alias1 = "uint32";
168   /// <summary>
169   /// An other alias around the 'unsigned int' type.
170   /// </summary>
171   public const string UInt32Alias2 = "uint";
172  
173   /// <summary>
174   /// The alias around the 'unsigned long' type.
175   /// </summary>
176   public const string UInt64Alias1 = "uint64";
177   /// <summary>
178   /// An other alias around the 'unsigned long' type.
179   /// </summary>
180   public const string UInt64Alias2 = "ulong";
181  
182   /// <summary>
183   /// The alias around the 'SByte' type.
184   /// </summary>
185   public const string SByteAlias = "sbyte";
186  
187   /// <summary>
188   /// The alias around the 'string' type.
189   /// </summary>
190   public const string StringAlias = "string";
191  
192   /// <summary>
193   /// The alias around the 'TimeSpan' type.
194   /// </summary>
195   public const string TimeSpanAlias = "timespan";
196  
197   #endregion
198  
199   #region Fields
200   private static StringDictionary _aliases = new StringDictionary();
201   #endregion
202  
203   #region Constructor (s) / Destructor
204   /// <summary>
205   /// Creates a new instance of the TypeAliasFactory class.
206   /// </summary>
207   /// <remarks>
208   /// <p>
209   /// This is a utility class, and as such has no publicly visible
210   /// constructors.
211   /// </p>
212   /// </remarks>
213 0 private TypeAliasResolver() {}
214  
215   /// <summary>
216   /// Initialises the static properties of the TypeAliasResolver class.
217   /// </summary>
218 1 static TypeAliasResolver()
219   {
220   // Initialize a dictionary with some fully qualifiaed name
221 1 _aliases [TypeAliasResolver.ArrayListAlias1] = typeof (ArrayList).FullName;
222 1 _aliases [TypeAliasResolver.ArrayListAlias2] = typeof (ArrayList).FullName;
223  
224 1 _aliases [TypeAliasResolver.BoolAlias1] = typeof (bool).FullName;
225 1 _aliases [TypeAliasResolver.BoolAlias2] = typeof (bool).FullName;
226  
227 1 _aliases [TypeAliasResolver.ByteAlias] = typeof (byte).FullName;
228  
229 1 _aliases [TypeAliasResolver.CharAlias] = typeof (char).FullName;
230  
231 1 _aliases [TypeAliasResolver.DateAlias1] = typeof (DateTime).FullName;
232 1 _aliases [TypeAliasResolver.DateAlias2] = typeof (DateTime).FullName;
233  
234 1 _aliases [TypeAliasResolver.DecimalAlias] = typeof (decimal).FullName;
235  
236 1 _aliases [TypeAliasResolver.DoubleAlias] = typeof (double).FullName;
237  
238 1 _aliases [TypeAliasResolver.FloatAlias1] = typeof (float).FullName;
239 1 _aliases [TypeAliasResolver.FloatAlias2] = typeof (float).FullName;
240  
241 1 _aliases [TypeAliasResolver.GuidAlias] = typeof (System.Guid).FullName;
242  
243 1 _aliases [TypeAliasResolver.HashtableAlias1] = typeof (Hashtable).FullName;
244 1 _aliases [TypeAliasResolver.HashtableAlias2] = typeof (Hashtable).FullName;
245 1 _aliases [TypeAliasResolver.HashtableAlias3] = typeof (Hashtable).FullName;
246  
247 1 _aliases [TypeAliasResolver.Int16Alias1] = typeof (short).FullName;
248 1 _aliases [TypeAliasResolver.Int16Alias2] = typeof (short).FullName;
249  
250 1 _aliases [TypeAliasResolver.Int32Alias1] = typeof (int).FullName;
251 1 _aliases [TypeAliasResolver.Int32Alias2] = typeof (int).FullName;
252 1 _aliases [TypeAliasResolver.Int32Alias3] = typeof (int).FullName;
253  
254 1 _aliases [TypeAliasResolver.Int64Alias1] = typeof (long).FullName;
255 1 _aliases [TypeAliasResolver.Int64Alias2] = typeof (long).FullName;
256  
257 1 _aliases [TypeAliasResolver.UInt16Alias1] = typeof (ushort).FullName;
258 1 _aliases [TypeAliasResolver.UInt16Alias2] = typeof (ushort).FullName;
259  
260 1 _aliases [TypeAliasResolver.UInt32Alias1] = typeof (uint).FullName;
261 1 _aliases [TypeAliasResolver.UInt32Alias2] = typeof (uint).FullName;
262  
263 1 _aliases [TypeAliasResolver.UInt64Alias1] = typeof (ulong).FullName;
264 1 _aliases [TypeAliasResolver.UInt64Alias2] = typeof (ulong).FullName;
265  
266 1 _aliases [TypeAliasResolver.SByteAlias] = typeof (sbyte).FullName;
267  
268 1 _aliases [TypeAliasResolver.StringAlias] = typeof (string).FullName;
269  
270 1 _aliases [TypeAliasResolver.TimeSpanAlias] = typeof (string).FullName;
271  
272   }
273   #endregion
274  
275   #region Methods
276  
277   /// <summary>
278   /// Resolves the supplied type name.
279   /// </summary>
280   /// <remarks>
281   /// <p>
282   /// If the supplied type name is an alias, the fully resolved
283   /// type name is returned. If no alias could be found that matches
284   /// the supplied type name, then the type name will be returned as is.
285   /// </p>
286   /// </remarks>
287   /// <param name="type">The supplied type name.</param>
288   /// <returns>
289   /// If the supplied type name is an alias, the fully resolved
290   /// type name is returned. If no alias could be found that matches
291   /// the supplied type name, then the type name will be returned as is.
292   /// </returns>
293 37 public static string Resolve (string type)
294   {
295 37 if (type != null)
296   {
297 37 if (_aliases.ContainsKey (type.ToLower ()))
298   {
299 21 return _aliases [type] as string;
300   }
301   }
302 16 return type;
303   }
304  
305  
306   /// <summary>
307   /// Instantiate a 'Primitive' Type.
308   /// </summary>
309   /// <param name="typeCode">a typeCode.</param>
310   /// <returns>An object.</returns>
311 48 public static object InstantiatePrimitiveType(TypeCode typeCode)
312   {
313 48 object resultObject = null;
314  
315 48 switch(typeCode)
316   {
317   case TypeCode.Boolean :
318 1 resultObject = new Boolean();
319 1 break;
320   case TypeCode.Byte :
321 1 resultObject = new Byte();
322 1 break;
323   case TypeCode.Char :
324 1 resultObject = new Char();
325 1 break;
326   case TypeCode.DateTime :
327 0 resultObject = new DateTime();
328 0 break;
329   case TypeCode.Decimal :
330 1 resultObject = new Decimal();
331 1 break;
332   case TypeCode.Double :
333 1 resultObject = new Double();
334 1 break;
335   case TypeCode.Int16 :
336 1 resultObject = new Int16();
337 1 break;
338   case TypeCode.Int32 :
339 12 resultObject = new Int32();
340 12 break;
341   case TypeCode.Int64 :
342 1 resultObject = new Int64();
343 1 break;
344   case TypeCode.SByte :
345 0 resultObject = new SByte();
346 0 break;
347   case TypeCode.Single :
348 1 resultObject = new Single();
349 1 break;
350   case TypeCode.String :
351 28 resultObject = "";
352 28 break;
353   case TypeCode.UInt16 :
354 0 resultObject = new UInt16();
355 0 break;
356   case TypeCode.UInt32 :
357 0 resultObject = new UInt32();
358 0 break;
359   case TypeCode.UInt64 :
360 0 resultObject = new UInt64();
361 0 break;
362   }
363 48 return resultObject;
364   }
365  
366   #endregion
367  
368   }
369   }
370