~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/BooleanConverter.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 2001-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
 
 
21
 
namespace log4net.Util.TypeConverters
22
 
{
23
 
        /// <summary>
24
 
        /// Type converter for Boolean.
25
 
        /// </summary>
26
 
        /// <remarks>
27
 
        /// <para>
28
 
        /// Supports conversion from string to <c>bool</c> type.
29
 
        /// </para>
30
 
        /// </remarks>
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
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
 
                /// Convert the source object to the type supported by this object
58
 
                /// </summary>
59
 
                /// <param name="source">the object to convert</param>
60
 
                /// <returns>the converted object</returns>
61
 
                /// <remarks>
62
 
                /// <para>
63
 
                /// Uses the <see cref="Boolean.Parse"/> method to convert the
64
 
                /// <see cref="String"/> argument to a <see cref="Boolean"/>.
65
 
                /// </para>
66
 
                /// </remarks>
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"/>
70
 
                /// method.
71
 
                /// </exception>
72
 
                public object ConvertFrom(object source)
73
 
                {
74
 
                        string str = source as string;
75
 
                        if (str != null)
76
 
                        {
77
 
                                return bool.Parse(str);
78
 
                        }
79
 
                        throw ConversionNotSupportedException.Create(typeof(bool), source);
80
 
                }
81
 
 
82
 
                #endregion
83
 
        }
84
 
}