You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ym...@apache.org on 2002/08/13 14:59:51 UTC

cvs commit: jakarta-avalon-excalibur/csframework/src/cs/Util Converter.cs

ymikulski    2002/08/13 05:59:51

  Added:       csframework/src/cs/Util Converter.cs
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/csframework/src/cs/Util/Converter.cs
  
  Index: Converter.cs
  ===================================================================
  ///
  /// Copyright (C) The Apache Software Foundation. All rights reserved.
  ///
  /// This software is published under the terms of the Apache Software License
  /// version 1.1, a copy of which has been included  with this distribution in
  /// the LICENSE.txt file.
  ///
  using System;
  
  namespace Apache.Avalon.Util
  {
  	internal class Converter
  	{
  
  		internal static object ChangeType(object value, Type type, object defaultValue)
  		{
  			object result;
  
  			try
  			{
  				result = Convert.ChangeType(value, type); 
  			}
  			catch (Exception e)
  			{
  				if (defaultValue == null)
  				{
  					throw new InvalidCastException("The Convertion failed.", e);
  				}
  				else
  				{
  					result = defaultValue;
  				}
  			}
  			
  			return result;
  		}
  	}
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>