1
#region Copyright & License
3
// Copyright 2004-2005 The Apache Software Foundation
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
9
// http://www.apache.org/licenses/LICENSE-2.0
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.
22
namespace log4net.Util.TypeConverters
25
/// Supports conversion from string to <see cref="Type"/> type.
29
/// Supports conversion from string to <see cref="Type"/> type.
32
/// <seealso cref="ConverterRegistry"/>
33
/// <seealso cref="IConvertFrom"/>
34
/// <seealso cref="IConvertTo"/>
35
/// <author>Nicko Cadell</author>
36
internal class TypeConverter : IConvertFrom
38
#region Implementation of IConvertFrom
41
/// Can the source type be converted to the type supported by this object
43
/// <param name="sourceType">the type to convert</param>
44
/// <returns>true if the conversion is possible</returns>
47
/// Returns <c>true</c> if the <paramref name="sourceType"/> is
48
/// the <see cref="String"/> type.
51
public bool CanConvertFrom(Type sourceType)
53
return (sourceType == typeof(string));
57
/// Overrides the ConvertFrom method of IConvertFrom.
59
/// <param name="source">the object to convert to a Type</param>
60
/// <returns>the Type</returns>
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.
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"/>
74
public object ConvertFrom(object source)
76
string str = source as string;
79
return SystemInfo.GetTypeFromString(str, true, true);
81
throw ConversionNotSupportedException.Create(typeof(Type), source);