/// <summary>
/// Reads the values from an <see cref="IDataRecord"/> and assigns the read values to this
/// object's properties. The database column's name is used to as the key, so the value
/// will not be found if any aliases are used or not all columns were selected.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataRecord"/> to read the values from. Must already be ready to be read from.</param>
        public static void ReadValues(this CharacterTemplateTable source, System.Data.IDataRecord dataRecord)
        {
            System.Int32 i;

            i = dataRecord.GetOrdinal("ai_id");

            source.AIID = (System.Nullable <NetGore.AI.AIID>)(System.Nullable <NetGore.AI.AIID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("alliance_id");

            source.AllianceID = (DemoGame.AllianceID)(DemoGame.AllianceID) dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("body_id");

            source.BodyID = (DemoGame.BodyID)(DemoGame.BodyID) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("chat_dialog");

            source.ChatDialog = (System.Nullable <NetGore.Features.NPCChat.NPCChatDialogID>)(System.Nullable <NetGore.Features.NPCChat.NPCChatDialogID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("exp");

            source.Exp = (System.Int32)(System.Int32) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("give_cash");

            source.GiveCash = (System.Int32)(System.Int32) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("give_exp");

            source.GiveExp = (System.Int32)(System.Int32) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("id");

            source.ID = (DemoGame.CharacterTemplateID)(DemoGame.CharacterTemplateID) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("level");

            source.Level = (System.Int16)(System.Int16) dataRecord.GetInt16(i);

            i = dataRecord.GetOrdinal("move_speed");

            source.MoveSpeed = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("name");

            source.Name = (System.String)(System.String) dataRecord.GetString(i);

            i = dataRecord.GetOrdinal("respawn");

            source.Respawn = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("shop_id");

            source.ShopID = (System.Nullable <NetGore.Features.Shops.ShopID>)(System.Nullable <NetGore.Features.Shops.ShopID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("statpoints");

            source.StatPoints = (System.Int32)(System.Int32) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("stat_agi");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.Agi, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_defence");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.Defence, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_int");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.Int, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxhit");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxHit, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxhp");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxHP, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxmp");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxMP, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_minhit");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.MinHit, (System.Int32)(System.Int16) dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_str");

            source.SetStat((DemoGame.StatType)DemoGame.StatType.Str, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
        }
        /// <summary>
        /// Reads the values from an <see cref="IDataReader"/> and assigns the read values to this
        /// object's properties. Unlike ReadValues(), this method not only doesn't require
        /// all values to be in the <see cref="IDataReader"/>, but also does not require the values in
        /// the <see cref="IDataReader"/> to be a defined field for the table this class represents.
        /// Because of this, you need to be careful when using this method because values
        /// can easily be skipped without any indication.
        /// </summary>
        /// <param name="source">The object to add the extension method to.</param>
        /// <param name="dataRecord">The <see cref="IDataReader"/> to read the values from. Must already be ready to be read from.</param>
        public static void TryReadValues(this CharacterTemplateTable source, IDataRecord dataRecord)
        {
            for (var i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "ai_id":
                    source.AIID = (Nullable <AIID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "alliance_id":
                    source.AllianceID = (AllianceID)dataRecord.GetByte(i);
                    break;

                case "body_id":
                    source.BodyID = (BodyID)dataRecord.GetUInt16(i);
                    break;

                case "chat_dialog":
                    source.ChatDialog =
                        (Nullable <NPCChatDialogID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "exp":
                    source.Exp = dataRecord.GetInt32(i);
                    break;

                case "give_cash":
                    source.GiveCash = dataRecord.GetUInt16(i);
                    break;

                case "give_exp":
                    source.GiveExp = dataRecord.GetUInt16(i);
                    break;

                case "id":
                    source.ID = (CharacterTemplateID)dataRecord.GetUInt16(i);
                    break;

                case "level":
                    source.Level = dataRecord.GetByte(i);
                    break;

                case "move_speed":
                    source.MoveSpeed = dataRecord.GetUInt16(i);
                    break;

                case "name":
                    source.Name = dataRecord.GetString(i);
                    break;

                case "respawn":
                    source.Respawn = dataRecord.GetUInt16(i);
                    break;

                case "shop_id":
                    source.ShopID = (Nullable <ShopID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "statpoints":
                    source.StatPoints = dataRecord.GetInt32(i);
                    break;

                case "stat_agi":
                    source.SetStat(StatType.Agi, dataRecord.GetInt16(i));
                    break;

                case "stat_defence":
                    source.SetStat(StatType.Defence, dataRecord.GetInt16(i));
                    break;

                case "stat_int":
                    source.SetStat(StatType.Int, dataRecord.GetInt16(i));
                    break;

                case "stat_maxhit":
                    source.SetStat(StatType.MaxHit, dataRecord.GetInt16(i));
                    break;

                case "stat_maxhp":
                    source.SetStat(StatType.MaxHP, dataRecord.GetInt16(i));
                    break;

                case "stat_maxmp":
                    source.SetStat(StatType.MaxMP, dataRecord.GetInt16(i));
                    break;

                case "stat_minhit":
                    source.SetStat(StatType.MinHit, dataRecord.GetInt16(i));
                    break;

                case "stat_str":
                    source.SetStat(StatType.Str, dataRecord.GetInt16(i));
                    break;
                }
            }
        }
/// <summary>
/// Reads the values from an <see cref="IDataReader"/> and assigns the read values to this
/// object's properties. Unlike ReadValues(), this method not only doesn't require
/// all values to be in the <see cref="IDataReader"/>, but also does not require the values in
/// the <see cref="IDataReader"/> to be a defined field for the table this class represents.
/// Because of this, you need to be careful when using this method because values
/// can easily be skipped without any indication.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataReader"/> to read the values from. Must already be ready to be read from.</param>
        public static void TryReadValues(this CharacterTemplateTable source, System.Data.IDataRecord dataRecord)
        {
            for (int i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "ai_id":
                    source.AIID = (System.Nullable <NetGore.AI.AIID>)(System.Nullable <NetGore.AI.AIID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "alliance_id":
                    source.AllianceID = (DemoGame.AllianceID)(DemoGame.AllianceID) dataRecord.GetByte(i);
                    break;


                case "body_id":
                    source.BodyID = (DemoGame.BodyID)(DemoGame.BodyID) dataRecord.GetUInt16(i);
                    break;


                case "chat_dialog":
                    source.ChatDialog = (System.Nullable <NetGore.Features.NPCChat.NPCChatDialogID>)(System.Nullable <NetGore.Features.NPCChat.NPCChatDialogID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "exp":
                    source.Exp = (System.Int32)(System.Int32) dataRecord.GetInt32(i);
                    break;


                case "give_cash":
                    source.GiveCash = (System.Int32)(System.Int32) dataRecord.GetInt32(i);
                    break;


                case "give_exp":
                    source.GiveExp = (System.Int32)(System.Int32) dataRecord.GetInt32(i);
                    break;


                case "id":
                    source.ID = (DemoGame.CharacterTemplateID)(DemoGame.CharacterTemplateID) dataRecord.GetUInt16(i);
                    break;


                case "level":
                    source.Level = (System.Int16)(System.Int16) dataRecord.GetInt16(i);
                    break;


                case "move_speed":
                    source.MoveSpeed = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
                    break;


                case "name":
                    source.Name = (System.String)(System.String) dataRecord.GetString(i);
                    break;


                case "respawn":
                    source.Respawn = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
                    break;


                case "shop_id":
                    source.ShopID = (System.Nullable <NetGore.Features.Shops.ShopID>)(System.Nullable <NetGore.Features.Shops.ShopID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "statpoints":
                    source.StatPoints = (System.Int32)(System.Int32) dataRecord.GetInt32(i);
                    break;


                case "stat_agi":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.Agi, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_defence":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.Defence, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_int":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.Int, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_maxhit":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxHit, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_maxhp":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxHP, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_maxmp":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.MaxMP, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_minhit":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.MinHit, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;


                case "stat_str":
                    source.SetStat((DemoGame.StatType)DemoGame.StatType.Str, (System.Int32)(System.Int16) dataRecord.GetInt16(i));
                    break;
                }
            }
        }
        /// <summary>
        /// Reads the values from an <see cref="IDataRecord"/> and assigns the read values to this
        /// object's properties. The database column's name is used to as the key, so the value
        /// will not be found if any aliases are used or not all columns were selected.
        /// </summary>
        /// <param name="source">The object to add the extension method to.</param>
        /// <param name="dataRecord">The <see cref="IDataRecord"/> to read the values from. Must already be ready to be read from.</param>
        public static void ReadValues(this CharacterTemplateTable source, IDataRecord dataRecord)
        {
            Int32 i;

            i = dataRecord.GetOrdinal("ai_id");

            source.AIID = (Nullable <AIID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("alliance_id");

            source.AllianceID = (AllianceID)dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("body_id");

            source.BodyID = (BodyID)dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("chat_dialog");

            source.ChatDialog = (Nullable <NPCChatDialogID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("exp");

            source.Exp = dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("give_cash");

            source.GiveCash = dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("give_exp");

            source.GiveExp = dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("id");

            source.ID = (CharacterTemplateID)dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("level");

            source.Level = dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("move_speed");

            source.MoveSpeed = dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("name");

            source.Name = dataRecord.GetString(i);

            i = dataRecord.GetOrdinal("respawn");

            source.Respawn = dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("shop_id");

            source.ShopID = (Nullable <ShopID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("statpoints");

            source.StatPoints = dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("stat_agi");

            source.SetStat(StatType.Agi, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_defence");

            source.SetStat(StatType.Defence, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_int");

            source.SetStat(StatType.Int, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxhit");

            source.SetStat(StatType.MaxHit, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxhp");

            source.SetStat(StatType.MaxHP, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_maxmp");

            source.SetStat(StatType.MaxMP, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_minhit");

            source.SetStat(StatType.MinHit, dataRecord.GetInt16(i));

            i = dataRecord.GetOrdinal("stat_str");

            source.SetStat(StatType.Str, dataRecord.GetInt16(i));
        }