/// <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 ViewUserCharacterTable 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 "body_id": source.BodyID = (BodyID)dataRecord.GetUInt16(i); break; case "cash": source.Cash = dataRecord.GetInt32(i); break; case "character_template_id": source.CharacterTemplateID = (Nullable <CharacterTemplateID>)(dataRecord.IsDBNull(i) ? (ushort?)null : 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 "hp": source.HP = dataRecord.GetInt16(i); break; case "id": source.ID = dataRecord.GetInt32(i); break; case "level": source.Level = dataRecord.GetByte(i); break; case "load_map_id": source.LoadMapID = (MapID)dataRecord.GetUInt16(i); break; case "load_x": source.LoadX = dataRecord.GetUInt16(i); break; case "load_y": source.LoadY = dataRecord.GetUInt16(i); break; case "move_speed": source.MoveSpeed = dataRecord.GetUInt16(i); break; case "mp": source.MP = dataRecord.GetInt16(i); break; case "name": source.Name = dataRecord.GetString(i); break; case "respawn_map_id": source.RespawnMapID = (Nullable <MapID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i)); break; case "respawn_x": source.RespawnX = dataRecord.GetFloat(i); break; case "respawn_y": source.RespawnY = dataRecord.GetFloat(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.StatAgi = dataRecord.GetInt16(i); break; case "stat_defence": source.StatDefence = dataRecord.GetInt16(i); break; case "stat_int": source.StatInt = dataRecord.GetInt16(i); break; case "stat_maxhit": source.StatMaxhit = dataRecord.GetInt16(i); break; case "stat_maxhp": source.StatMaxhp = dataRecord.GetInt16(i); break; case "stat_maxmp": source.StatMaxmp = dataRecord.GetInt16(i); break; case "stat_minhit": source.StatMinhit = dataRecord.GetInt16(i); break; case "stat_str": source.StatStr = 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 ViewUserCharacterTable 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("body_id"); source.BodyID = (DemoGame.BodyID)(DemoGame.BodyID) dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("cash"); source.Cash = (System.Int32)(System.Int32) dataRecord.GetInt32(i); i = dataRecord.GetOrdinal("character_template_id"); source.CharacterTemplateID = (System.Nullable <DemoGame.CharacterTemplateID>)(System.Nullable <DemoGame.CharacterTemplateID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : 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("hp"); source.HP = (DemoGame.SPValueType)(DemoGame.SPValueType) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("id"); source.ID = (System.Int32)(System.Int32) dataRecord.GetInt32(i); i = dataRecord.GetOrdinal("level"); source.Level = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("load_map_id"); source.LoadMapID = (NetGore.World.MapID)(NetGore.World.MapID) dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("load_x"); source.LoadX = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("load_y"); source.LoadY = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("move_speed"); source.MoveSpeed = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("mp"); source.MP = (DemoGame.SPValueType)(DemoGame.SPValueType) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("name"); source.Name = (System.String)(System.String) dataRecord.GetString(i); i = dataRecord.GetOrdinal("respawn_map_id"); source.RespawnMapID = (System.Nullable <NetGore.World.MapID>)(System.Nullable <NetGore.World.MapID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i)); i = dataRecord.GetOrdinal("respawn_x"); source.RespawnX = (System.Single)(System.Single) dataRecord.GetFloat(i); i = dataRecord.GetOrdinal("respawn_y"); source.RespawnY = (System.Single)(System.Single) dataRecord.GetFloat(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.StatAgi = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_defence"); source.StatDefence = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_int"); source.StatInt = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxhit"); source.StatMaxhit = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxhp"); source.StatMaxhp = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxmp"); source.StatMaxmp = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_minhit"); source.StatMinhit = (System.Int16)(System.Int16) dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_str"); source.StatStr = (System.Int16)(System.Int16) dataRecord.GetInt16(i); }
/// <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 ViewUserCharacterTable 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("body_id"); source.BodyID = (BodyID)dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("cash"); source.Cash = dataRecord.GetInt32(i); i = dataRecord.GetOrdinal("character_template_id"); source.CharacterTemplateID = (Nullable <CharacterTemplateID>)(dataRecord.IsDBNull(i) ? (ushort?)null : 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("hp"); source.HP = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("id"); source.ID = dataRecord.GetInt32(i); i = dataRecord.GetOrdinal("level"); source.Level = dataRecord.GetByte(i); i = dataRecord.GetOrdinal("load_map_id"); source.LoadMapID = (MapID)dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("load_x"); source.LoadX = dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("load_y"); source.LoadY = dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("move_speed"); source.MoveSpeed = dataRecord.GetUInt16(i); i = dataRecord.GetOrdinal("mp"); source.MP = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("name"); source.Name = dataRecord.GetString(i); i = dataRecord.GetOrdinal("respawn_map_id"); source.RespawnMapID = (Nullable <MapID>)(dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i)); i = dataRecord.GetOrdinal("respawn_x"); source.RespawnX = dataRecord.GetFloat(i); i = dataRecord.GetOrdinal("respawn_y"); source.RespawnY = dataRecord.GetFloat(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.StatAgi = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_defence"); source.StatDefence = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_int"); source.StatInt = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxhit"); source.StatMaxhit = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxhp"); source.StatMaxhp = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_maxmp"); source.StatMaxmp = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_minhit"); source.StatMinhit = dataRecord.GetInt16(i); i = dataRecord.GetOrdinal("stat_str"); source.StatStr = 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 ViewUserCharacterTable 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 "body_id": source.BodyID = (DemoGame.BodyID)(DemoGame.BodyID) dataRecord.GetUInt16(i); break; case "cash": source.Cash = (System.Int32)(System.Int32) dataRecord.GetInt32(i); break; case "character_template_id": source.CharacterTemplateID = (System.Nullable <DemoGame.CharacterTemplateID>)(System.Nullable <DemoGame.CharacterTemplateID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : 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 "hp": source.HP = (DemoGame.SPValueType)(DemoGame.SPValueType) dataRecord.GetInt16(i); break; case "id": source.ID = (System.Int32)(System.Int32) dataRecord.GetInt32(i); break; case "level": source.Level = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "load_map_id": source.LoadMapID = (NetGore.World.MapID)(NetGore.World.MapID) dataRecord.GetUInt16(i); break; case "load_x": source.LoadX = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); break; case "load_y": source.LoadY = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); break; case "move_speed": source.MoveSpeed = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i); break; case "mp": source.MP = (DemoGame.SPValueType)(DemoGame.SPValueType) dataRecord.GetInt16(i); break; case "name": source.Name = (System.String)(System.String) dataRecord.GetString(i); break; case "respawn_map_id": source.RespawnMapID = (System.Nullable <NetGore.World.MapID>)(System.Nullable <NetGore.World.MapID>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i)); break; case "respawn_x": source.RespawnX = (System.Single)(System.Single) dataRecord.GetFloat(i); break; case "respawn_y": source.RespawnY = (System.Single)(System.Single) dataRecord.GetFloat(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.StatAgi = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_defence": source.StatDefence = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_int": source.StatInt = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_maxhit": source.StatMaxhit = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_maxhp": source.StatMaxhp = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_maxmp": source.StatMaxmp = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_minhit": source.StatMinhit = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; case "stat_str": source.StatStr = (System.Int16)(System.Int16) dataRecord.GetInt16(i); break; } } }