You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/08/19 23:19:52 UTC

cvs commit: logging-log4net/src/Util/TypeConverters PatternLayoutConverter.cs ConverterRegistry.cs

nicko       2004/08/19 14:19:52

  Modified:    src/Util/TypeConverters ConverterRegistry.cs
  Added:       src/Util/TypeConverters PatternLayoutConverter.cs
  Log:
  Added PatternLayoutConverter
  
  Revision  Changes    Path
  1.5       +3 -14     logging-log4net/src/Util/TypeConverters/ConverterRegistry.cs
  
  Index: ConverterRegistry.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/TypeConverters/ConverterRegistry.cs,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConverterRegistry.cs	30 Jul 2004 14:15:30 -0000	1.4
  +++ ConverterRegistry.cs	19 Aug 2004 21:19:52 -0000	1.5
  @@ -60,6 +60,7 @@
   			AddConverter(typeof(bool), typeof(BooleanConverter));
   			AddConverter(typeof(System.Text.Encoding), typeof(EncodingConverter));
   			AddConverter(typeof(System.Type), typeof(TypeConverter));
  +			AddConverter(typeof(log4net.Layout.PatternLayout), typeof(PatternLayoutConverter));
   			AddConverter(typeof(log4net.Util.PatternString), typeof(PatternStringConverter));
   		}
   
  @@ -104,14 +105,8 @@
   			// TODO: Support inheriting type converters.
   
   			// i.e. getting a type converter for a base of destinationType
  -			IConvertTo converter = null;
  -
   			// Lookup in the static registry
  -			object obj = s_registry.m_type2converter[sourceType];
  -			if ((obj != null) && (obj is IConvertTo))
  -			{
  -				converter = (IConvertTo)obj;
  -			}
  +			IConvertTo converter = s_registry.m_type2converter[sourceType] as IConvertTo;
   
   			if (converter == null)
   			{
  @@ -141,14 +136,8 @@
   			// TODO: Support inheriting type converters.
   
   			// i.e. getting a type converter for a base of destinationType
  -			IConvertFrom converter = null;
  -
   			// Lookup in the static registry
  -			object obj = s_registry.m_type2converter[destinationType];
  -			if ((obj != null) && (obj is IConvertFrom))
  -			{
  -				converter = (IConvertFrom)obj;
  -			}
  +			IConvertFrom converter = s_registry.m_type2converter[destinationType] as IConvertFrom;
   
   			if (converter == null)
   			{
  
  
  
  1.1                  logging-log4net/src/Util/TypeConverters/PatternLayoutConverter.cs
  
  Index: PatternLayoutConverter.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System;
  using System.Text;
  
  using log4net.Layout;
  
  namespace log4net.Util.TypeConverters
  {
  	/// <summary>
  	/// Implementation of <see cref="IConvertFrom"/> that converts 
  	/// a string into a <see cref="PatternLayout"/>.
  	/// </summary>
  	/// <author>Nicko Cadell</author>
  	public class PatternLayoutConverter : IConvertFrom
  	{
  		#region Implementation of IConvertFrom
  
  		/// <summary>
  		/// Overrides the CanConvertFrom method of IConvertFrom.
  		/// The ITypeDescriptorContext interface provides the context for the
  		/// conversion. Typically this interface is used at design time to 
  		/// provide information about the design-time container.
  		/// </summary>
  		/// <param name="sourceType"></param>
  		/// <returns>true if the source is a string</returns>
  		public bool CanConvertFrom(System.Type sourceType)
  		{
  			return (sourceType == typeof(string));
  		}
  
  		/// <summary>
  		/// Overrides the ConvertFrom method of IConvertFrom.
  		/// </summary>
  		/// <param name="source">the object to convert to a PatternLayout</param>
  		/// <returns>the PatternLayout</returns>
  		public object ConvertFrom(object source) 
  		{
  			if (source is string) 
  			{
  				return new PatternLayout((string)source);
  			}
  			throw ConversionNotSupportedException.Create(typeof(PatternLayout), source);
  		}
  
  		#endregion
  	}
  }