~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Util/TypeConverters/.svn/text-base/TypeConverter.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2004-2005 The Apache Software Foundation
4
 
//
5
 
// Licensed under the Apache License, Version 2.0 (the "License");
6
 
// you may not use this file except in compliance with the License.
7
 
// You may obtain a copy of the License at
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
11
 
// Unless required by applicable law or agreed to in writing, software
12
 
// distributed under the License is distributed on an "AS IS" BASIS,
13
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
// See the License for the specific language governing permissions and
15
 
// limitations under the License.
16
 
//
17
 
#endregion
18
 
 
19
 
using System;
20
 
using System.Text;
21
 
 
22
 
namespace log4net.Util.TypeConverters
23
 
{
24
 
        /// <summary>
25
 
        /// Supports conversion from string to <see cref="Type"/> type.
26
 
        /// </summary>
27
 
        /// <remarks>
28
 
        /// <para>
29
 
        /// Supports conversion from string to <see cref="Type"/> type.
30
 
        /// </para>
31
 
        /// </remarks>
32
 
        /// <seealso cref="ConverterRegistry"/>
33
 
        /// <seealso cref="IConvertFrom"/>
34
 
        /// <seealso cref="IConvertTo"/>
35
 
        /// <author>Nicko Cadell</author>
36
 
        internal class TypeConverter : IConvertFrom 
37
 
        {
38
 
                #region Implementation of IConvertFrom
39
 
 
40
 
                /// <summary>
41
 
                /// Can the source type be converted to the type supported by this object
42
 
                /// </summary>
43
 
                /// <param name="sourceType">the type to convert</param>
44
 
                /// <returns>true if the conversion is possible</returns>
45
 
                /// <remarks>
46
 
                /// <para>
47
 
                /// Returns <c>true</c> if the <paramref name="sourceType"/> is
48
 
                /// the <see cref="String"/> type.
49
 
                /// </para>
50
 
                /// </remarks>
51
 
                public bool CanConvertFrom(Type sourceType) 
52
 
                {
53
 
                        return (sourceType == typeof(string));
54
 
                }
55
 
 
56
 
                /// <summary>
57
 
                /// Overrides the ConvertFrom method of IConvertFrom.
58
 
                /// </summary>
59
 
                /// <param name="source">the object to convert to a Type</param>
60
 
                /// <returns>the Type</returns>
61
 
                /// <remarks>
62
 
                /// <para>
63
 
                /// Uses the <see cref="Type.GetType(string,bool)"/> method to convert the
64
 
                /// <see cref="String"/> argument to a <see cref="Type"/>.
65
 
                /// Additional effort is made to locate partially specified types
66
 
                /// by searching the loaded assemblies.
67
 
                /// </para>
68
 
                /// </remarks>
69
 
                /// <exception cref="ConversionNotSupportedException">
70
 
                /// The <paramref name="source"/> object cannot be converted to the
71
 
                /// target type. To check for this condition use the <see cref="CanConvertFrom"/>
72
 
                /// method.
73
 
                /// </exception>
74
 
                public object ConvertFrom(object source) 
75
 
                {
76
 
                        string str = source as string;
77
 
                        if (str != null)
78
 
                        {
79
 
                                return SystemInfo.GetTypeFromString(str, true, true);
80
 
                        }
81
 
                        throw ConversionNotSupportedException.Create(typeof(Type), source);
82
 
                }
83
 
 
84
 
                #endregion
85
 
        }
86
 
}