using System; #region " Đ Copyright 2005-07 to Marcos Meli - http://www.marcosmeli.com.ar" // Errors, suggestions, contributions, send a mail to: marcos@filehelpers.com. #endregion namespace FileHelpers { /// /// Base class to provide bidirectional /// Field - String convertion. /// public abstract class ConverterBase { private static string mDefaultDateTimeFormat = "ddMMyyyy"; /// /// Allow you to set the default Date Format used for the converter. /// With the same format that the .NET framework. /// By default: "ddMMyyyy" /// public static string DefaultDateTimeFormat { get { return mDefaultDateTimeFormat; } set { try { string tmp = DateTime.Now.ToString(value); } catch { throw new BadUsageException("The format: '" + value + " is invalid for the DateTime Converter."); } mDefaultDateTimeFormat= value; } } /// /// Convert a string in the file to a field value. /// /// The string to convert. /// The field value. public abstract object StringToField(string from); /// /// Convert a field value to an string to write this to the file. /// /// The basic implementation performs a: from.ToString(); /// The field values to convert. /// The string representing the field value. public virtual string FieldToString(object from) { if (from == null) return string.Empty; else return from.ToString(); } /// If the class retures false the engines donīt pass null values to the converter. If true the engines pass all the values to the converter. protected internal virtual bool CustomNullHandling { get { return false; } } internal Type mDestinationType; /// /// Thorws a ConvertException with the passed values /// /// The source string. /// The custom error msg. protected void ThrowConvertException(string from, string errorMsg) { throw new ConvertException(from, mDestinationType, errorMsg); } // internal object mDefaultValue; // /// // /// Indicates // /// // protected object DefaultValueFromField // { // get // { // return mDefaultValue; // } // } } }