SmartInt class - v2.0, soon v2.1

SmartInt class - v2.0, soon v2.1

Old forum URL: forums.lhotka.net/forums/t/1460.aspx


david.wendelken posted on Wednesday, October 11, 2006

I did up a v2.0 SmartInt class awhile back (think SmartDate for an Int) and it seems to be holding up pretty well in practice.

I'm in the process of changing its name to SmartInt32 (so I can later do a SmartInt16, etc.), plus verifying that it works with v2.1.

I have two questions:

1) The SmartDate class used resource files to store error message strings.  I can muddle my way thru the English resource files, and maybe even the French, but after that I'm well beyond my level of language competency.  How do people handle that?  Just put English in the other language resource files until someone replaces it with the correct language text?  Don't touch the other language files and it all works ok somehow?   (I really don't have any interest in learning all about this feature right now, I have enough on my plate!)  I just need to know enough to get going.

2) To make the SmartInt class really useful, I had to make a number of extensions to the SafeDateReader class.  What would be the best way to handle that when it comes to submitting code?

I don't want to get into the problem of having two versions of SafeDataReader to keep track of, mine and Rocky's!  I would prefer to just give mine to Rocky! :)

 

 

david.wendelken replied on Wednesday, October 18, 2006

I've been doing some thinking about how I handled the changes to SafeDataReader.

I'm thinking I should subclass SafeDataReader (SmarterSafeDataReader?? :) instead of changing it to support SmartInt16, SmartInt32, SmartBool, etc.

Comments?  Suggestions?

 

razorkai replied on Wednesday, October 18, 2006

Hi David

I'm a tad confused by the whole Csla Contrib thing.  I have just been looking for the SmartInt stuff you said you uploaded but I can't see it anywhere on the contrib website.  I am curious to take a look.  Can you explain where I can download it from?

Thanks.

david.wendelken replied on Wednesday, October 18, 2006

this is the SmartInt class.

Given some free time, I would refactor it into SmartInt32...

========================================================

using System;

using Csla.Properties;

namespace Csla

{

/// <summary>

/// Provides an integer data type that understands the concept

/// of an empty value.

/// </summary>

/// <remarks>

/// See Chapter 5 for a full discussion of the need for a similar

/// data type and the design choices behind it. Basically, we are

/// using the same approach to handle integers instead of ints.

/// </remarks>

[Serializable()]

public struct SmartInt : IComparable

{

private int _int;

private bool _initialized;

private bool _emptyIsMax;

private string _format;

#region Constructors

/// <summary>

/// Creates a new SmartInt object.

/// </summary>

/// <param name="emptyIsMin">Indicates whether an empty int is the min or max int value.</param>

public SmartInt(bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

_initialized = false;

// provide a dummy value to allow real initialization

_int = int.MinValue;

if (!_emptyIsMax)

Int = int.MinValue;

else

Int = int.MaxValue;

}

/// <summary>

/// Creates a new SmartInt object.

/// </summary>

/// <remarks>

/// The SmartInt created will use the min possible

/// int to represent an empty int.

/// </remarks>

/// <param name="Value">The initial value of the object.</param>

public SmartInt(int value)

{

_emptyIsMax = false;

_format = null;

_initialized = false;

_int = int.MinValue;

Int = value;

}

/// <summary>

/// Creates a new SmartInt object.

/// </summary>

/// <param name="Value">The initial value of the object.</param>

/// <param name="EmptyIsMin">Indicates whether an empty int is the min or max int value.</param>

public SmartInt(int value, bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

_initialized = false;

_int = int.MinValue;

Int = value;

}

/// <summary>

/// Creates a new SmartInt object.

/// </summary>

/// <remarks>

/// The SmartInt created will use the min possible

/// int to represent an empty int.

/// </remarks>

/// <param name="Value">The initial value of the object (as text).</param>

public SmartInt(string value)

{

_emptyIsMax = false;

_format = null;

_initialized = true;

_int = int.MinValue;

this.Text = value;

}

/// <summary>

/// Creates a new SmartInt object.

/// </summary>

/// <param name="Value">The initial value of the object (as text).</param>

/// <param name="EmptyIsMin">Indicates whether an empty int is the min or max int value.</param>

public SmartInt(string value, bool emptyIsMin)

{

_emptyIsMax = !emptyIsMin;

_format = null;

_initialized = true;

_int = int.MinValue;

this.Text = value;

}

#endregion

#region Text Support

/// <summary>

/// Gets or sets the format string used to format a int

/// value when it is returned as text.

/// </summary>

/// <remarks>

/// The format string should follow the requirements for the

/// .NET <see cref="System.String.Format"/> statement.

/// </remarks>

/// <value>A format string.</value>

public string FormatString

{

get

{

if (_format == null)

_format = "d";

return _format;

}

set

{

_format = value;

}

}

/// <summary>

/// Gets or sets the int value.

/// </summary>

/// <remarks>

/// <para>

/// This property can be used to set the int value by passing a

/// text representation of the int. Any text int representation

/// that can be parsed by the .NET runtime is valid.

/// </para><para>

/// When the int value is retrieved via this property, the text

/// is formatted by using the format specified by the

/// <see cref="FormatString" /> property. The default is the

/// short int format (d).

/// </para>

/// </remarks>

public string Text

{

get { return IntToString(this.Int, FormatString, !_emptyIsMax); }

set { this.Int = StringToInt(value, !_emptyIsMax); }

}

#endregion

#region Int Support

/// <summary>

/// Gets or sets the int value.

/// </summary>

public int Int

{

get

{

if (!_initialized)

{

_int = int.MinValue;

_initialized = true;

}

return _int;

}

set

{

_int = value;

_initialized = true;

}

}

#endregion

#region System.Object overrides

/// <summary>

/// Returns a text representation of the int value.

/// </summary>

public override string ToString()

{

return this.Text;

}

/// <summary>

/// Compares this object to another <see cref="SmartInt"/>

/// for equality.

/// </summary>

public override bool Equals(object obj)

{

if (obj is SmartInt)

{

SmartInt tmp = (SmartInt)obj;

if (this.IsEmpty && tmp.IsEmpty)

return true;

else

return this.Int.Equals(tmp.Int);

}

else if (obj is int)

return this.Int.Equals((int)obj);

else if (obj is string)

return (this.CompareTo(obj.ToString()) == 0);

else

return false;

}

/// <summary>

/// Returns a hash code for this object.

/// </summary>

public override int GetHashCode()

{

return this.Int.GetHashCode();

}

#endregion

#region DBValue

/// <summary>

/// Gets a database-friendly version of the int value.

/// </summary>

/// <remarks>

/// <para>

/// If the SmartInt contains an empty int, this returns <see cref="DBNull"/>.

/// Otherwise the actual int value is returned as type Int.

/// </para><para>

/// This property is very useful when setting parameter values for

/// a Command object, since it automatically stores null values into

/// the database for empty int values.

/// </para><para>

/// When you also use the SafeDataReader and its GetSmartInt method,

/// you can easily read a null value from the database back into a

/// SmartInt object so it remains considered as an empty int value.

/// </para>

/// </remarks>

public object DBValue

{

get

{

if (this.IsEmpty)

return DBNull.Value;

else

return this.Int;

}

}

#endregion

#region Empty Ints

/// <summary>

/// Gets a value indicating whether this object contains an empty int.

/// </summary>

public bool IsEmpty

{

get

{

if (!_emptyIsMax)

return this.Int.Equals(int.MinValue);

else

return this.Int.Equals(int.MaxValue);

}

}

/// <summary>

/// Gets a value indicating whether an empty int is the

/// min or max possible int value.

/// </summary>

/// <remarks>

/// Whether an empty int is considered to be the smallest or largest possible

/// int is only important for comparison operations. This allows you to

/// compare an empty int with a real int and get a meaningful result.

/// </remarks>

public bool EmptyIsMin

{

get { return !_emptyIsMax; }

}

#endregion

#region Conversion Functions

/// <summary>

/// Converts a string value into a SmartInt.

/// </summary>

/// <param name="value">String containing the int value.</param>

/// <returns>A new SmartInt containing the int value.</returns>

/// <remarks>

/// EmptyIsMin will default to <see langword="true"/>.

/// </remarks>

public static SmartInt Parse(string value)

{

return new SmartInt(value);

}

/// <summary>

/// Converts a string value into a SmartInt.

/// </summary>

/// <param name="value">String containing the int value.</param>

/// <param name="emptyIsMin">Indicates whether an empty int is the min or max int value.</param>

/// <returns>A new SmartInt containing the int value.</returns>

public static SmartInt Parse(string value, bool emptyIsMin)

{

return new SmartInt(value, emptyIsMin);

}

/// <summary>

/// Converts a text int representation into a Int value.

/// </summary>

/// <remarks>

/// An empty string is assumed to represent an empty int. An empty int

/// is returned as the MinValue of the Int datatype.

/// </remarks>

/// <param name="Value">The text representation of the int.</param>

/// <returns>A Int value.</returns>

public static int StringToInt(string value)

{

return StringToInt(value, true);

}

/// <summary>

/// Converts a text int representation into a Int value.

/// </summary>

/// <remarks>

/// An empty string is assumed to represent an empty int. An empty int

/// is returned as the MinValue or MaxValue of the Int datatype depending

/// on the EmptyIsMin parameter.

/// </remarks>

/// <param name="Value">The text representation of the int.</param>

/// <param name="EmptyIsMin">Indicates whether an empty int is the min or max int value.</param>

/// <returns>A Int value.</returns>

public static int StringToInt(string value, bool emptyIsMin)

{

int tmp;

if (String.IsNullOrEmpty(value))

{

if (emptyIsMin)

return int.MinValue;

else

return int.MaxValue;

}

else if (int.TryParse(value, out tmp))

return tmp;

else

{

string lint = value.Trim().ToLower();

throw new ArgumentException("Invalid integer value."); // TODO: Resources.StringToIntException);

}

}

/// <summary>

/// Converts a int value into a text representation.

/// </summary>

/// <remarks>

/// The int is considered empty if it matches the min value for

/// the Int datatype. If the int is empty, this

/// method returns an empty string. Otherwise it returns the int

/// value formatted based on the FormatString parameter.

/// </remarks>

/// <param name="Value">The int value to convert.</param>

/// <param name="FormatString">The format string used to format the int into text.</param>

/// <returns>Text representation of the int value.</returns>

public static string IntToString(

int value, string formatString)

{

return IntToString(value, formatString, true);

}

/// <summary>

/// Converts a int value into a text representation.

/// </summary>

/// <remarks>

/// Whether the int value is considered empty is determined by

/// the EmptyIsMin parameter value. If the int is empty, this

/// method returns an empty string. Otherwise it returns the int

/// value formatted based on the FormatString parameter.

/// </remarks>

/// <param name="Value">The int value to convert.</param>

/// <param name="FormatString">The format string used to format the int into text.</param>

/// <param name="EmptyIsMin">Indicates whether an empty int is the min or max int value.</param>

/// <returns>Text representation of the int value.</returns>

public static string IntToString(

int value, string formatString, bool emptyIsMin)

{

if (emptyIsMin && value == int.MinValue)

return string.Empty;

else if (!emptyIsMin && value == int.MaxValue)

return string.Empty;

else

return string.Format("{0:" + formatString + "}", value);

}

#endregion

#region Manipulation Functions

/// <summary>

/// Compares one SmartInt to another.

/// </summary>

/// <remarks>

/// This method works the same as the <see cref="int.CompareTo"/> method

/// on the Int inttype, with the exception that it

/// understands the concept of empty int values.

/// </remarks>

/// <param name="Value">The int to which we are being compared.</param>

/// <returns>A value indicating if the comparison int is less than, equal to or greater than this int.</returns>

public int CompareTo(SmartInt value)

{

if (this.IsEmpty && value.IsEmpty)

return 0;

else

return _int.CompareTo(value.Int);

}

/// <summary>

/// Compares one SmartInt to another.

/// </summary>

/// <remarks>

/// This method works the same as the <see cref="int.CompareTo"/> method

/// on the Int inttype, with the exception that it

/// understands the concept of empty int values.

/// </remarks>

/// <param name="obj">The int to which we are being compared.</param>

/// <returns>A value indicating if the comparison int is less than, equal to or greater than this int.</returns>

int IComparable.CompareTo(object value)

{

if (value is SmartInt)

return CompareTo((SmartInt)value);

else

throw new ArgumentException("Not a SmartInt to compare to."); //TODO: Resources.ValueNotSmartIntException);

}

/// <summary>

/// Compares a SmartInt to a text int value.

/// </summary>

/// <param name="Value">The int to which we are being compared.</param>

/// <returns>A value indicating if the comparison int is less than, equal to or greater than this int.</returns>

public int CompareTo(string value)

{

return this.Int.CompareTo(StringToInt(value, !_emptyIsMax));

}

/// <summary>

/// Compares a SmartInt to a int value.

/// </summary>

/// <param name="Value">The int to which we are being compared.</param>

/// <returns>A value indicating if the comparison int is less than, equal to or greater than this int.</returns>

public int CompareTo(int value)

{

return this.Int.CompareTo(value);

}

/// <summary>

/// Adds an integer value onto the object.

/// </summary>

public int Add(int value)

{

if (IsEmpty)

return this.Int;

else

return this.Int + value;

}

/// <summary>

/// Subtracts an integer value from the object.

/// </summary>

public int Subtract(int value)

{

if (IsEmpty)

return this.Int;

else

return this.Int - value;

}

#endregion

#region Operators

public static bool operator ==(SmartInt obj1, SmartInt obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartInt obj1, SmartInt obj2)

{

return !obj1.Equals(obj2);

}

public static bool operator ==(SmartInt obj1, int obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartInt obj1, int obj2)

{

return !obj1.Equals(obj2);

}

public static bool operator ==(SmartInt obj1, string obj2)

{

return obj1.Equals(obj2);

}

public static bool operator !=(SmartInt obj1, string obj2)

{

return !obj1.Equals(obj2);

}

public static SmartInt operator +(SmartInt start, int span)

{

return new SmartInt(start.Add(span), start.EmptyIsMin);

}

public static SmartInt operator -(SmartInt start, int span)

{

return new SmartInt(start.Subtract(span), start.EmptyIsMin);

}

public static int operator -(SmartInt start, SmartInt finish)

{

return start.Subtract(finish.Int);

}

public static bool operator >(SmartInt obj1, SmartInt obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartInt obj1, SmartInt obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >(SmartInt obj1, int obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartInt obj1, int obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >(SmartInt obj1, string obj2)

{

return obj1.CompareTo(obj2) > 0;

}

public static bool operator <(SmartInt obj1, string obj2)

{

return obj1.CompareTo(obj2) < 0;

}

public static bool operator >=(SmartInt obj1, SmartInt obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartInt obj1, SmartInt obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

public static bool operator >=(SmartInt obj1, int obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartInt obj1, int obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

public static bool operator >=(SmartInt obj1, string obj2)

{

return obj1.CompareTo(obj2) >= 0;

}

public static bool operator <=(SmartInt obj1, string obj2)

{

return obj1.CompareTo(obj2) <= 0;

}

#endregion

}

}

david.wendelken replied on Wednesday, October 18, 2006

this is the updated SafeDataReader so it also knows about SmartInt.

this was from v2.0.3 (ditto for SmartInt).

haven't tested against 2.1 yet.

basically, I did a search on SmartDate and mirrored the code for SmartInt.

I think this would be better done as a subclass of SafeDataReader.  I'm going to experiment on that next week.

==============================================

using System;

using System.Data;

namespace Csla.Data

{

/// <summary>

/// This is a DataReader that 'fixes' any null values before

/// they are returned to our business code.

/// </summary>

public class SafeDataReader : IDataReader

{

private IDataReader _dataReader;

/// <summary>

/// Get a reference to the underlying data reader

/// object that actually contains the data from

/// the data source.

/// </summary>

protected IDataReader DataReader

{

get { return _dataReader; }

}

/// <summary>

/// Initializes the SafeDataReader object to use data from

/// the provided DataReader object.

/// </summary>

/// <param name="DataReader">The source DataReader object containing the data.</param>

public SafeDataReader(IDataReader dataReader)

{

_dataReader = dataReader;

}

/// <summary>

/// Gets a string value from the datareader.

/// </summary>

/// <remarks>

/// Returns empty string for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public string GetString(string name)

{

return GetString(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a string value from the datareader.

/// </summary>

/// <remarks>

/// Returns empty string for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual string GetString(int i)

{

if (_dataReader.IsDBNull(i))

return string.Empty;

else

return _dataReader.GetString(i);

}

 

/// <summary>

/// Gets a value of type <see cref="System.Object" /> from the datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public object GetValue(string name)

{

return GetValue(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a value of type <see cref="System.Object" /> from the datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public virtual object GetValue(int i)

{

if (_dataReader.IsDBNull(i))

return null;

else

return _dataReader.GetValue(i);

}

/// <summary>

/// Gets an integer from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public int GetInt32(string name)

{

return GetInt32(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets an integer from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual int GetInt32(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetInt32(i);

}

/// <summary>

/// Gets a double from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public double GetDouble(string name)

{

return GetDouble(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a double from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual double GetDouble(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetDouble(i);

}

/// <summary>

/// Gets a <see cref="SmartDate" /> from the datareader.

/// </summary>

/// <remarks>

/// A null is converted into min possible date

/// See Chapter 5 for more details on the SmartDate class.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public Csla.SmartDate GetSmartDate(string name)

{

return GetSmartDate(_dataReader.GetOrdinal(name), true);

}

/// <summary>

/// Gets a <see cref="SmartInt" /> from the datareader.

/// </summary>

/// <remarks>

/// A null is converted into min possible int.

/// See Chapter 5 for more details on the SmartDate class, and transpose the concepts to SmartInt32.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public Csla.SmartInt GetSmartInt(string name)

{

return GetSmartInt(_dataReader.GetOrdinal(name), true);

}

/// <summary>

/// Gets a <see cref="SmartDate" /> from the datareader.

/// </summary>

/// <remarks>

/// A null is converted into the min possible date

/// See Chapter 5 for more details on the SmartDate class.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual Csla.SmartDate GetSmartDate(int i)

{

return GetSmartDate(i, true);

}

/// <summary>

/// Gets a <see cref="SmartDate" /> from the datareader.

/// </summary>

/// <remarks>

/// A null is converted into either the min or max possible date

/// depending on the MinIsEmpty parameter. See Chapter 5 for more

/// details on the SmartDate class.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

/// <param name="minIsEmpty">

/// A flag indicating whether the min or max

/// value of a data means an empty date.</param>

public Csla.SmartDate GetSmartDate(string name, bool minIsEmpty)

{

return GetSmartDate(_dataReader.GetOrdinal(name), minIsEmpty);

}

/// <summary>

/// Gets a <see cref="SmartInt" /> from the datareader.

/// </summary>

/// <remarks>

/// A null is converted into either the min or max possible int

/// depending on the MinIsEmpty parameter. See Chapter 5 for more

/// details on the SmartDate class, and transpose concepts to SmartInt.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

/// <param name="minIsEmpty">

/// A flag indicating whether the min or max

/// value of a data means an empty int.</param>

public Csla.SmartInt GetSmartInt(string name, bool minIsEmpty)

{

return GetSmartInt(_dataReader.GetOrdinal(name), minIsEmpty);

}

public virtual Csla.SmartDate GetSmartDate(

int i, bool minIsEmpty)

{

if (_dataReader.IsDBNull(i))

return new Csla.SmartDate(minIsEmpty);

else

return new Csla.SmartDate(

_dataReader.GetDateTime(i), minIsEmpty);

}

public virtual Csla.SmartInt GetSmartInt(

int i, bool minIsEmpty)

{

if (_dataReader.IsDBNull(i))

return new Csla.SmartInt(minIsEmpty);

else

return new Csla.SmartInt(

_dataReader.GetInt32(i), minIsEmpty);

}

/// <summary>

/// Gets a Guid value from the datareader.

/// </summary>

/// <remarks>

/// Returns Guid.Empty for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public System.Guid GetGuid(string name)

{

return GetGuid(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a Guid value from the datareader.

/// </summary>

/// <remarks>

/// Returns Guid.Empty for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual System.Guid GetGuid(int i)

{

if (_dataReader.IsDBNull(i))

return Guid.Empty;

else

return _dataReader.GetGuid(i);

}

/// <summary>

/// Reads the next row of data from the datareader.

/// </summary>

public bool Read()

{

return _dataReader.Read();

}

/// <summary>

/// Moves to the next result set in the datareader.

/// </summary>

public bool NextResult()

{

return _dataReader.NextResult();

}

/// <summary>

/// Closes the datareader.

/// </summary>

public void Close()

{

_dataReader.Close();

}

/// <summary>

/// Returns the depth property value from the datareader.

/// </summary>

public int Depth

{

get

{

return _dataReader.Depth;

}

}

/// <summary>

/// Returns the FieldCount property from the datareader.

/// </summary>

public int FieldCount

{

get

{

return _dataReader.FieldCount;

}

}

/// <summary>

/// Gets a boolean value from the datareader.

/// </summary>

/// <remarks>

/// Returns <see langword="false" /> for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public bool GetBoolean(string name)

{

return GetBoolean(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a boolean value from the datareader.

/// </summary>

/// <remarks>

/// Returns <see langword="false" /> for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual bool GetBoolean(int i)

{

if (_dataReader.IsDBNull(i))

return false;

else

return _dataReader.GetBoolean(i);

}

/// <summary>

/// Gets a byte value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public byte GetByte(string name)

{

return GetByte(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a byte value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual byte GetByte(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetByte(i);

}

/// <summary>

/// Invokes the GetBytes method of the underlying datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public Int64 GetBytes(string name, Int64 fieldOffset,

byte[] buffer, int bufferoffset, int length)

{

return GetBytes(_dataReader.GetOrdinal(name), fieldOffset, buffer, bufferoffset, length);

}

/// <summary>

/// Invokes the GetBytes method of the underlying datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual Int64 GetBytes(int i, Int64 fieldOffset,

byte[] buffer, int bufferoffset, int length)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetBytes(i, fieldOffset, buffer, bufferoffset, length);

}

/// <summary>

/// Gets a char value from the datareader.

/// </summary>

/// <remarks>

/// Returns Char.MinValue for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public char GetChar(string name)

{

return GetChar(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a char value from the datareader.

/// </summary>

/// <remarks>

/// Returns Char.MinValue for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual char GetChar(int i)

{

if (_dataReader.IsDBNull(i))

return char.MinValue;

else

{

char[] myChar = new char[1];

_dataReader.GetChars(i, 0, myChar, 0, 1);

return myChar[0];

}

}

/// <summary>

/// Invokes the GetChars method of the underlying datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public Int64 GetChars(string name, Int64 fieldoffset,

char[] buffer, int bufferoffset, int length)

{

return GetChars(_dataReader.GetOrdinal(name), fieldoffset, buffer, bufferoffset, length);

}

/// <summary>

/// Invokes the GetChars method of the underlying datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual Int64 GetChars(int i, Int64 fieldoffset,

char[] buffer, int bufferoffset, int length)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetChars(i, fieldoffset, buffer, bufferoffset, length);

}

/// <summary>

/// Invokes the GetData method of the underlying datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public IDataReader GetData(string name)

{

return GetData(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Invokes the GetData method of the underlying datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public virtual IDataReader GetData(int i)

{

return _dataReader.GetData(i);

}

/// <summary>

/// Invokes the GetDataTypeName method of the underlying datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public string GetDataTypeName(string name)

{

return GetDataTypeName(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Invokes the GetDataTypeName method of the underlying datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public virtual string GetDataTypeName(int i)

{

return _dataReader.GetDataTypeName(i);

}

/// <summary>

/// Gets a date value from the datareader.

/// </summary>

/// <remarks>

/// Returns DateTime.MinValue for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public virtual DateTime GetDateTime(string name)

{

return GetDateTime(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a date value from the datareader.

/// </summary>

/// <remarks>

/// Returns DateTime.MinValue for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual DateTime GetDateTime(int i)

{

if (_dataReader.IsDBNull(i))

return DateTime.MinValue;

else

return _dataReader.GetDateTime(i);

}

/// <summary>

/// Gets a decimal value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public decimal GetDecimal(string name)

{

return GetDecimal(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a decimal value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual decimal GetDecimal(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetDecimal(i);

}

/// <summary>

/// Invokes the GetFieldType method of the underlying datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public Type GetFieldType(string name)

{

return GetFieldType(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Invokes the GetFieldType method of the underlying datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public virtual Type GetFieldType(int i)

{

return _dataReader.GetFieldType(i);

}

/// <summary>

/// Gets a Single value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public float GetFloat(string name)

{

return GetFloat(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a Single value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual float GetFloat(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetFloat(i);

}

/// <summary>

/// Gets a Short value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public short GetInt16(string name)

{

return GetInt16(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a Short value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual short GetInt16(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetInt16(i);

}

/// <summary>

/// Gets a Long value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="name">Name of the column containing the value.</param>

public Int64 GetInt64(string name)

{

return GetInt64(_dataReader.GetOrdinal(name));

}

/// <summary>

/// Gets a Long value from the datareader.

/// </summary>

/// <remarks>

/// Returns 0 for null.

/// </remarks>

/// <param name="i">Ordinal column position of the value.</param>

public virtual Int64 GetInt64(int i)

{

if (_dataReader.IsDBNull(i))

return 0;

else

return _dataReader.GetInt64(i);

}

/// <summary>

/// Invokes the GetName method of the underlying datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public virtual string GetName(int i)

{

return _dataReader.GetName(i);

}

/// <summary>

/// Gets an ordinal value from the datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public int GetOrdinal(string name)

{

return _dataReader.GetOrdinal(name);

}

/// <summary>

/// Invokes the GetSchemaTable method of the underlying datareader.

/// </summary>

public DataTable GetSchemaTable()

{

return _dataReader.GetSchemaTable();

}

 

/// <summary>

/// Invokes the GetValues method of the underlying datareader.

/// </summary>

public int GetValues(object[] values)

{

return _dataReader.GetValues(values);

}

/// <summary>

/// Returns the IsClosed property value from the datareader.

/// </summary>

public bool IsClosed

{

get

{

return _dataReader.IsClosed;

}

}

/// <summary>

/// Invokes the IsDBNull method of the underlying datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public virtual bool IsDBNull(int i)

{

return _dataReader.IsDBNull(i);

}

/// <summary>

/// Returns a value from the datareader.

/// </summary>

/// <param name="name">Name of the column containing the value.</param>

public object this[string name]

{

get

{

object val = _dataReader[name];

if (DBNull.Value.Equals(val))

return null;

else

return val;

}

}

/// <summary>

/// Returns a value from the datareader.

/// </summary>

/// <param name="i">Ordinal column position of the value.</param>

public virtual object this[int i]

{

get

{

if (_dataReader.IsDBNull(i))

return null;

else

return _dataReaderIdea <img src=" src="/emoticons/emotion-55.gif">;

}

}

/// <summary>

/// Returns the RecordsAffected property value from the underlying datareader.

/// </summary>

public int RecordsAffected

{

get

{

return _dataReader.RecordsAffected;

}

}

#region IDisposable Support

private bool _disposedValue; // To detect redundant calls

// IDisposable

protected virtual void Dispose(bool disposing)

{

if (!_disposedValue)

{

if (disposing)

{

// free unmanaged resources when explicitly called

_dataReader.Dispose();

}

// free shared unmanaged resources

}

_disposedValue = true;

}

// This code added by Visual Basic to correctly implement the disposable pattern.

public void Dispose()

{

// Do not change this code. Put cleanup code in Dispose(bool disposing) above.

Dispose(true);

GC.SuppressFinalize(this);

}

#endregion

}

}

Copyright (c) Marimer LLC