/// <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 AccountTable source, System.Data.IDataRecord dataRecord)
        {
            for (int i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "creator_ip":
                    source.CreatorIp = (System.UInt32)(System.UInt32) dataRecord.GetUInt32(i);
                    break;


                case "current_ip":
                    source.CurrentIp = (System.Nullable <System.UInt32>)(System.Nullable <System.UInt32>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt32>)null : dataRecord.GetUInt32(i));
                    break;


                case "email":
                    source.Email = (System.String)(System.String) dataRecord.GetString(i);
                    break;


                case "friends":
                    source.Friends = (System.String)(System.String) dataRecord.GetString(i);
                    break;


                case "id":
                    source.ID = (DemoGame.AccountID)(DemoGame.AccountID) dataRecord.GetInt32(i);
                    break;


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


                case "password":
                    source.Password = (System.String)(System.String) dataRecord.GetString(i);
                    break;


                case "permissions":
                    source.Permissions = (DemoGame.UserPermissions)(DemoGame.UserPermissions) dataRecord.GetByte(i);
                    break;


                case "time_created":
                    source.TimeCreated = (System.DateTime)(System.DateTime) dataRecord.GetDateTime(i);
                    break;


                case "time_last_login":
                    source.TimeLastLogin = (System.DateTime)(System.DateTime) dataRecord.GetDateTime(i);
                    break;
                }
            }
        }
Пример #2
0
        /// <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 AccountTable source, IDataRecord dataRecord)
        {
            for (var i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "creator_ip":
                    source.CreatorIp = dataRecord.GetUInt32(i);
                    break;

                case "current_ip":
                    source.CurrentIp = (dataRecord.IsDBNull(i) ? (uint?)null : dataRecord.GetUInt32(i));
                    break;

                case "email":
                    source.Email = dataRecord.GetString(i);
                    break;

                case "id":
                    source.ID = (AccountID)dataRecord.GetInt32(i);
                    break;

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

                case "password":
                    source.Password = dataRecord.GetString(i);
                    break;

                case "permissions":
                    source.Permissions = (UserPermissions)dataRecord.GetByte(i);
                    break;

                case "time_created":
                    source.TimeCreated = dataRecord.GetDateTime(i);
                    break;

                case "time_last_login":
                    source.TimeLastLogin = dataRecord.GetDateTime(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 AccountTable source, System.Data.IDataRecord dataRecord)
        {
            System.Int32 i;

            i = dataRecord.GetOrdinal("creator_ip");

            source.CreatorIp = (System.UInt32)(System.UInt32) dataRecord.GetUInt32(i);

            i = dataRecord.GetOrdinal("current_ip");

            source.CurrentIp = (System.Nullable <System.UInt32>)(System.Nullable <System.UInt32>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt32>)null : dataRecord.GetUInt32(i));

            i = dataRecord.GetOrdinal("email");

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

            i = dataRecord.GetOrdinal("friends");

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

            i = dataRecord.GetOrdinal("id");

            source.ID = (DemoGame.AccountID)(DemoGame.AccountID) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("name");

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

            i = dataRecord.GetOrdinal("password");

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

            i = dataRecord.GetOrdinal("permissions");

            source.Permissions = (DemoGame.UserPermissions)(DemoGame.UserPermissions) dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("time_created");

            source.TimeCreated = (System.DateTime)(System.DateTime) dataRecord.GetDateTime(i);

            i = dataRecord.GetOrdinal("time_last_login");

            source.TimeLastLogin = (System.DateTime)(System.DateTime) dataRecord.GetDateTime(i);
        }
Пример #4
0
        /// <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 AccountTable source, IDataRecord dataRecord)
        {
            Int32 i;

            i = dataRecord.GetOrdinal("creator_ip");

            source.CreatorIp = dataRecord.GetUInt32(i);

            i = dataRecord.GetOrdinal("current_ip");

            source.CurrentIp = (dataRecord.IsDBNull(i) ? (uint?)null : dataRecord.GetUInt32(i));

            i = dataRecord.GetOrdinal("email");

            source.Email = dataRecord.GetString(i);

            i = dataRecord.GetOrdinal("id");

            source.ID = (AccountID)dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("name");

            source.Name = dataRecord.GetString(i);

            i = dataRecord.GetOrdinal("password");

            source.Password = dataRecord.GetString(i);

            i = dataRecord.GetOrdinal("permissions");

            source.Permissions = (UserPermissions)dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("time_created");

            source.TimeCreated = dataRecord.GetDateTime(i);

            i = dataRecord.GetOrdinal("time_last_login");

            source.TimeLastLogin = dataRecord.GetDateTime(i);
        }