Click here to Skip to main content
15,895,084 members
Articles / Web Development / HTML

Transformalizing NorthWind

Rate me:
Please Sign up or sign in to vote.
4.95/5 (29 votes)
24 Jul 2014GPL37 min read 57.8K   341   53  
Combining de-normalization, transformation, replication, and awesome-ness.
#region License
// /*
// See license included in this library folder.
// */
#endregion

using System;
using Transformalize.Libs.FileHelpers.Attributes;
using Transformalize.Libs.FileHelpers.Converters;
using Transformalize.Libs.FileHelpers.Engines;
using Transformalize.Libs.FileHelpers.Enums;
using Transformalize.Libs.FileHelpers.Helpers;

namespace Transformalize.Libs.FileHelpers.ErrorHandling
{
    /// <summary>
    ///     Contains error information of the <see cref="FileHelperEngine" /> class.
    /// </summary>
    [DelimitedRecord("|")]
    [IgnoreFirst(2)]
#if NET_2_0
    [DebuggerDisplay("Line: {LineNumber}. Error: {ExceptionInfo.Message}.")]
#endif
    public sealed class ErrorInfo
    {
        internal ErrorInfo()
        {
        }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        internal int mLineNumber;

        /// <summary>The line number of the error</summary>
        public int LineNumber
        {
            get { return mLineNumber; }
        }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        [FieldQuoted(QuoteMode.OptionalForBoth)] internal string mRecordString = string.Empty;

        /// <summary>The string of the record of the error.</summary>
        public string RecordString
        {
            get { return mRecordString; }
        }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        [FieldConverter(typeof (ExceptionConverter))] [FieldQuoted(QuoteMode.OptionalForBoth)] internal Exception mExceptionInfo;

        /// <summary>The exception that indicates the error.</summary>
        public Exception ExceptionInfo
        {
            get { return mExceptionInfo; }
        }

        internal class ExceptionConverter : ConverterBase
        {
            public override string FieldToString(object from)
            {
                if (from == null)
                    return String.Empty;
                else
                {
                    if (from is ConvertException)
                        return "In the field '" + ((ConvertException) from).FieldName + "': " + ((ConvertException) from).Message.Replace(StringHelper.NewLine, " -> ");
                    else
                        return ((Exception) from).Message.Replace(StringHelper.NewLine, " -> ");
                }
            }

            public override object StringToField(string from)
            {
                return new Exception(from);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions