#region Apache License // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to you 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; #if !NETCF using System.Runtime.Serialization; #endif namespace log4net.Util.TypeConverters { /// /// Exception base type for conversion errors. /// /// /// /// This type extends . It /// does not add any new functionality but does differentiate the /// type of exception being thrown. /// /// /// Nicko Cadell /// Gert Driesen #if !NETCF [Serializable] #endif public class ConversionNotSupportedException : ApplicationException { #region Public Instance Constructors /// /// Constructor /// /// /// /// Initializes a new instance of the class. /// /// public ConversionNotSupportedException() { } /// /// Constructor /// /// A message to include with the exception. /// /// /// Initializes a new instance of the class /// with the specified message. /// /// public ConversionNotSupportedException(String message) : base(message) { } /// /// Constructor /// /// A message to include with the exception. /// A nested exception to include. /// /// /// Initializes a new instance of the class /// with the specified message and inner exception. /// /// public ConversionNotSupportedException(String message, Exception innerException) : base(message, innerException) { } #endregion Public Instance Constructors #region Protected Instance Constructors #if !NETCF /// /// Serialization constructor /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// /// /// Initializes a new instance of the class /// with serialized data. /// /// protected ConversionNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif #endregion Protected Instance Constructors #region Public Static Methods /// /// Creates a new instance of the class. /// /// The conversion destination type. /// The value to convert. /// An instance of the . /// /// /// Creates a new instance of the class. /// /// public static ConversionNotSupportedException Create(Type destinationType, object sourceValue) { return Create(destinationType, sourceValue, null); } /// /// Creates a new instance of the class. /// /// The conversion destination type. /// The value to convert. /// A nested exception to include. /// An instance of the . /// /// /// Creates a new instance of the class. /// /// public static ConversionNotSupportedException Create(Type destinationType, object sourceValue, Exception innerException) { if (sourceValue == null) { return new ConversionNotSupportedException("Cannot convert value [null] to type ["+destinationType+"]", innerException); } else { return new ConversionNotSupportedException("Cannot convert from type ["+sourceValue.GetType()+"] value ["+sourceValue+"] to type ["+destinationType+"]", innerException); } } #endregion Public Static Methods } }