/// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var formatProvider = (IFormatProvider)propertyMapData.TypeConverterOptions.CultureInfo;

            TimeSpan span;

            #if !NET_2_0 && !NET_3_5 && !PCL
            var timeSpanStyle = propertyMapData.TypeConverterOptions.TimeSpanStyle ?? TimeSpanStyles.None;
            if( !string.IsNullOrEmpty( propertyMapData.TypeConverterOptions.Format ) && TimeSpan.TryParseExact( text, propertyMapData.TypeConverterOptions.Format, formatProvider, timeSpanStyle, out span ) )
            {
                return span;
            }

            if( string.IsNullOrEmpty( propertyMapData.TypeConverterOptions.Format ) && TimeSpan.TryParse( text, formatProvider, out span ) )
            {
                return span;
            }
            #else
            if( TimeSpan.TryParse( text, out span ) )
            {
                return span;
            }
            #endif

            return base.ConvertFromString( text, row, propertyMapData );
        }
Beispiel #2
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            if( text == null )
            {
                return base.ConvertFromString( text, row, propertyMapData );
            }

            return new Guid( text );
        }
Beispiel #3
0
 /// <summary>
 /// Converts the string to an object.
 /// </summary>
 /// <param name="text">The string to convert to an object.</param>
 /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
 /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
 /// <returns>The object created from the string.</returns>
 public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
 {
     try
     {
         return Enum.Parse( type, text, true );
     }
     catch
     {
         return base.ConvertFromString( text, row, propertyMapData );
     }
 }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var numberStyle = propertyMapData.TypeConverterOptions.NumberStyle ?? NumberStyles.Float;

            decimal d;
            if( decimal.TryParse( text, numberStyle, propertyMapData.TypeConverterOptions.CultureInfo, out d ) )
            {
                return d;
            }

            return base.ConvertFromString( text, row, propertyMapData );
        }
Beispiel #5
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var numberStyle = propertyMapData.TypeConverterOptions.NumberStyle ?? NumberStyles.Integer;

            sbyte sb;
            if( sbyte.TryParse( text, numberStyle, propertyMapData.TypeConverterOptions.CultureInfo, out sb ) )
            {
                return sb;
            }

            return base.ConvertFromString( text, row, propertyMapData );
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            if( text == null )
            {
                return base.ConvertFromString( null, row, propertyMapData );
            }

            var formatProvider = (IFormatProvider)propertyMapData.TypeConverterOptions.CultureInfo.GetFormat( typeof( DateTimeFormatInfo ) ) ?? propertyMapData.TypeConverterOptions.CultureInfo;
            var dateTimeStyle = propertyMapData.TypeConverterOptions.DateTimeStyle ?? DateTimeStyles.None;

            return string.IsNullOrEmpty( propertyMapData.TypeConverterOptions.Format )
                ? DateTime.Parse( text, formatProvider, dateTimeStyle )
                : DateTime.ParseExact( text, propertyMapData.TypeConverterOptions.Format, formatProvider, dateTimeStyle );
        }
Beispiel #7
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            if( text != null && text.Length > 1 )
            {
                text = text.Trim();
            }

            char c;
            if( char.TryParse( text, out c ) )
            {
                return c;
            }

            return base.ConvertFromString( text, row, propertyMapData );
        }
Beispiel #8
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            Array array;
            var type = propertyMapData.Member.MemberType().GetElementType();

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var list = new List<object>();
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }

                array = (Array)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType(), list.Count );
                for( var i = 0; i < list.Count; i++ )
                {
                    array.SetValue( list[i], i );
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                var arraySize = indexEnd - propertyMapData.Index + 1;
                array = (Array)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType(), arraySize );
                var arrayIndex = 0;
                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    array.SetValue( row.GetField( type, i ), arrayIndex );
                    arrayIndex++;
                }
            }

            return array;
        }
Beispiel #9
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            if( text == null )
            {
                return string.Empty;
            }

            foreach( var nullValue in propertyMapData.TypeConverterOptions.NullValues )
            {
                if( text == nullValue )
                {
                    return null;
                }
            }

            return text;
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var dictionary = new Dictionary<string, string>();

            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                ? row.CurrentRecord.Length - 1
                : propertyMapData.IndexEnd;

            for( var i = propertyMapData.Index; i <= indexEnd; i++ )
            {
                string field;
                if( row.TryGetField( i, out field ) )
                {
                    dictionary.Add( row.FieldHeaders[i], field );
                }
            }

            return dictionary;
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var keyType = propertyMapData.Member.MemberType().GetGenericArguments()[0];
            var valueType = propertyMapData.Member.MemberType().GetGenericArguments()[1];
            var dictionaryType = typeof( Dictionary<,> );
            dictionaryType = dictionaryType.MakeGenericType( keyType, valueType );
            var dictionary = (IDictionary)ReflectionHelper.CreateInstance( dictionaryType );

            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                ? row.CurrentRecord.Length - 1
                : propertyMapData.IndexEnd;

            for( var i = propertyMapData.Index; i <= indexEnd; i++ )
            {
                var field = row.GetField( valueType, i );

                dictionary.Add( row.FieldHeaders[i], field );
            }

            return dictionary;
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            // Since we're using the PropertyType here, this converter can be used for multiple types
            // as long as they implement IList.
            var list = (IList)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType() );
            var type = propertyMapData.Member.MemberType().GetGenericArguments()[0];

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    var field = row.GetField( type, i );

                    list.Add( field );
                }
            }

            return list;
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var type = propertyMapData.Member.MemberType().GetGenericArguments()[0];
            var listType = typeof( List<> );
            listType = listType.MakeGenericType( type );
            var list = (IList)ReflectionHelper.CreateInstance( listType );

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    var field = row.GetField( type, i );

                    list.Add( field );
                }
            }

            return list;
        }
Beispiel #14
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            bool b;
            if( bool.TryParse( text, out b ) )
            {
                return b;
            }

            short sh;
            if( short.TryParse( text, out sh ) )
            {
                if( sh == 0 )
                {
                    return false;
                }
                if( sh == 1 )
                {
                    return true;
                }
            }

            var t = ( text ?? string.Empty ).Trim();
            foreach( var trueValue in propertyMapData.TypeConverterOptions.BooleanTrueValues )
            {
                if( propertyMapData.TypeConverterOptions.CultureInfo.CompareInfo.Compare( trueValue, t, CompareOptions.IgnoreCase ) == 0 )
                {
                    return true;
                }
            }

            foreach( var falseValue in propertyMapData.TypeConverterOptions.BooleanFalseValues )
            {
                if( propertyMapData.TypeConverterOptions.CultureInfo.CompareInfo.Compare( falseValue, t, CompareOptions.IgnoreCase ) == 0 )
                {
                    return false;
                }
            }

            return base.ConvertFromString( text, row, propertyMapData );
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var list = new ArrayList();

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var nameIndex = 0;
                while( true )
                {
                    string field;
                    if( !row.TryGetField( propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    string field;
                    if( row.TryGetField( i, out field ) )
                    {
                        list.Add( field );
                    }
                }
            }

            return list;
        }
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var trimmed = text.Trim(new char[] { ' ', '"', '\n' });

            return(TimeUtils.DateStringToDateTimeUtc(trimmed));
        }
 /// <summary>
 /// Converts the string to an object.
 /// </summary>
 /// <param name="text">The string to convert to an object.</param>
 /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
 /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
 /// <returns>The object created from the string.</returns>
 public virtual object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
 {
     throw new CsvTypeConverterException( "The conversion cannot be performed." );
 }
Beispiel #18
0
        /// <summary>
        /// Get bounce category
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        private BounceCat GetBounceCategory(ICsvReaderRow b)
        {
            var       value = b.GetField <string>("bounceCat");
            BounceCat bc    = BounceCat.Other;

            switch (value)
            {
            case "other": bc = BounceCat.Other;
                break;

            case "bad-mailbox": bc = BounceCat.BadMailbox;
                break;

            case "bad-domain": bc = BounceCat.BadDomain;
                break;

            case "inactive-mailbox": bc = BounceCat.InactiveMailbox;
                break;

            case "bad-configuration": bc = BounceCat.BadConfiguration;
                break;

            case "bad-connection": bc = BounceCat.BadConnection;
                break;

            case "content-related": bc = BounceCat.ContentRelated;
                break;

            case "invalid-sender": bc = BounceCat.InvalidSender;
                break;

            case "message-expired": bc = BounceCat.MessageExpired;
                break;

            case "no-answer-from-host": bc = BounceCat.NoAnswerFromHost;
                break;

            case "policy-related": bc = BounceCat.PolicyRelated;
                break;

            case "protocol-errors": bc = BounceCat.ProtocolErrors;
                break;

            case "quota-issues": bc = BounceCat.QuotaIssues;
                break;

            case "relaying-issues": bc = BounceCat.RelayingIssues;
                break;

            case "routing-errors": bc = BounceCat.RoutingErrors;
                break;

            case "spam-related": bc = BounceCat.SpamRelated;
                break;

            case "virus-related": bc = BounceCat.VirusRelated;
                break;

            default:
                break;
            }
            return(bc);
        }
Beispiel #19
0
 public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
 {
     return("test");
 }
 /// <summary>
 /// Throws an exception.
 /// </summary>
 /// <param name="text">The string to convert to an object.</param>
 /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
 /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
 /// <returns>The object created from the string.</returns>
 public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
 {
     throw new CsvTypeConverterException("Converting IEnumerable types is not supported for a single field. " +
                                         "If you want to do this, create your own ITypeConverter and register " +
                                         "it in the TypeConverterFactory by calling AddConverter.");
 }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            if( string.IsNullOrEmpty( text ) )
            {
                return null;
            }

            foreach( var nullValue in propertyMapData.TypeConverterOptions.NullValues )
            {
                if( text == nullValue )
                {
                    return null;
                }
            }

            return UnderlyingTypeConverter.ConvertFromString( text, row, propertyMapData );
        }
 /// <summary>
 /// Converts the string to an object.
 /// </summary>
 /// <param name="text">The string to convert to an object.</param>
 /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
 /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
 /// <returns>The object created from the string.</returns>
 public virtual object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
 {
     throw new CsvTypeConverterException("The conversion cannot be performed.");
 }
 /// <summary>
 /// Throws an exception.
 /// </summary>
 /// <param name="text">The string to convert to an object.</param>
 /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
 /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
 /// <returns>The object created from the string.</returns>
 public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
 {
     throw new CsvTypeConverterException( "Converting IEnumerable types is not supported for a single field. " +
                                          "If you want to do this, create your own ITypeConverter and register " +
                                          "it in the TypeConverterFactory by calling AddConverter." );
 }
Beispiel #24
0
 public object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
 {
     throw new NotImplementedException();
 }
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var dequotedText = text.Trim(new char[] { ' ', '"' });

            return(base.ConvertFromString(dequotedText, row, propertyMapData));
        }
 private static string GetColumn(ICsvReaderRow csv, string columnName)
 {
     return(csv.GetField <string>(columnName).Trim());
 }