Click here to Skip to main content
15,896,606 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
#undef GENERICS
//#define GENERICS
//#if NET_2_0

using System.ComponentModel;

//using System.ComponentModel.TypeConverter;

namespace Transformalize.Libs.FileHelpers.MasterDetail
{
    /// <summary>
    ///     <para>This class contains information of a Master record an their Details records.</para>
    ///     <para>
    ///         This class is used for the Read and Write operations of the <see cref="MasterDetailEngine" />.
    ///     </para>
    /// </summary>
#if ! GENERICS
#if NET_2_0
    [DebuggerDisplay("Master: {Master.ToString()} - Details: {Details.Length}")]
#endif
    [TypeConverter(typeof (ExpandableObjectConverter))]
    public class MasterDetails
    {
        /// <summary>Create an empty instance.</summary>
        public MasterDetails()
        {
            mDetails = mEmpty.mDetails;
        }

        /// <summary>Create a new instance with the specified values.</summary>
        /// <param name="master">The master record.</param>
        /// <param name="details">The details record.</param>
        public MasterDetails(object master, object[] details)
        {
            mMaster = master;
            mDetails = details;
        }

#if NET_2_0
		[DebuggerBrowsable(DebuggerBrowsableState.Never)] 
		#endif
        private static readonly MasterDetails mEmpty = new MasterDetails(null, new object[] {});

        /// <summary>Returns a canonical empty MasterDetail object.</summary>
        public static MasterDetails Empty
        {
            get { return mEmpty; }
        }

#if NET_2_0
		[DebuggerBrowsable(DebuggerBrowsableState.Never)] 
		#endif
        internal object mMaster;

        /// <summary>The Master record.</summary>
        public object Master
        {
            get { return mMaster; }
            set { mMaster = value; }
        }

#if NET_2_0
		[DebuggerBrowsable(DebuggerBrowsableState.Never)] 
		#endif
        internal object[] mDetails;

        /// <summary>An Array with the Detail records.</summary>
        [TypeConverter(typeof (ArrayConverter))]
        public object[] Details
        {
            get { return mDetails; }
            set { mDetails = value; }
        }

#else
	public class MasterDetails<M,D>
        where M : class
        where D : class
	{

		/// <summary>Create an empty instance.</summary>
		public MasterDetails()
		{
			mDetails = mEmpty.mDetails;
		}

		/// <summary>Create a new instance with the specified values.</summary>
		/// <param name="master">The master record.</param>
		/// <param name="details">The details record.</param>
		public MasterDetails(M master, D[] details)
		{
			mMaster = master;
			mDetails = details;
		}

		private static MasterDetails<M,D> mEmpty = new MasterDetails<M,D>(null, new D[] {});

		/// <summary>Returns a canonical empty MasterDetail object.</summary>
		public static MasterDetails<M,D> Empty
		{
			get { return mEmpty; }
		}

		internal M mMaster;

		/// <summary>The Master record.</summary>
		public M Master
		{
			get { return mMaster; }
			set { mMaster = value; }
		}

		internal D[] mDetails;

		/// <summary>An Array with the Detail records.</summary>
		public D[] Details
		{
			get { return mDetails; }
			set { mDetails = value; }
		}

#endif
    }
}

//#endif

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