1
#region Copyright & License
3
// Copyright 2001-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.
21
namespace log4net.Util.TypeConverters
24
/// Type converter for Boolean.
28
/// Supports conversion from string to <c>bool</c> type.
31
/// <seealso cref="ConverterRegistry"/>
32
/// <seealso cref="IConvertFrom"/>
33
/// <seealso cref="IConvertTo"/>
34
/// <author>Nicko Cadell</author>
35
/// <author>Gert Driesen</author>
36
internal class BooleanConverter : 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
/// Convert the source object to the type supported by this object
59
/// <param name="source">the object to convert</param>
60
/// <returns>the converted object</returns>
63
/// Uses the <see cref="Boolean.Parse"/> method to convert the
64
/// <see cref="String"/> argument to a <see cref="Boolean"/>.
67
/// <exception cref="ConversionNotSupportedException">
68
/// The <paramref name="source"/> object cannot be converted to the
69
/// target type. To check for this condition use the <see cref="CanConvertFrom"/>
72
public object ConvertFrom(object source)
74
string str = source as string;
77
return bool.Parse(str);
79
throw ConversionNotSupportedException.Create(typeof(bool), source);