|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using System.Reflection; |
|
22 using System.ComponentModel; |
|
23 |
|
24 namespace SymbianParserLib.TypeConverters |
|
25 { |
|
26 public class SymbianEnumConverter : EnumConverter |
|
27 { |
|
28 #region Constructors |
|
29 public SymbianEnumConverter( Type aType ) |
|
30 : base( aType ) |
|
31 { |
|
32 } |
|
33 #endregion |
|
34 |
|
35 #region From EnumConverter |
|
36 public override bool CanConvertFrom( ITypeDescriptorContext aContext, Type aSourceType ) |
|
37 { |
|
38 bool ret = base.CanConvertFrom( aContext, aSourceType ); |
|
39 // |
|
40 if ( aSourceType == typeof( uint ) ) |
|
41 { |
|
42 ret = true; |
|
43 } |
|
44 else if ( aSourceType == typeof( int ) ) |
|
45 { |
|
46 ret = true; |
|
47 } |
|
48 else if ( aSourceType == typeof( ulong ) ) |
|
49 { |
|
50 ret = true; |
|
51 } |
|
52 // |
|
53 return ret; |
|
54 } |
|
55 |
|
56 public override object ConvertFrom( ITypeDescriptorContext aContext, System.Globalization.CultureInfo aCulture, object aValue ) |
|
57 { |
|
58 object ret = null; |
|
59 // |
|
60 if ( ( aValue is uint ) || ( aValue is int ) || ( aValue is ulong ) ) |
|
61 { |
|
62 ret = Enum.ToObject( base.EnumType, aValue ); |
|
63 } |
|
64 else |
|
65 { |
|
66 ret = base.ConvertFrom( aContext, aCulture, aValue ); |
|
67 } |
|
68 // |
|
69 return ret; |
|
70 } |
|
71 #endregion |
|
72 } |
|
73 } |