Click here to Skip to main content
15,881,789 members
Articles / Programming Languages / C#

C# 2.0 Nullable Data Readers

Rate me:
Please Sign up or sign in to vote.
4.90/5 (43 votes)
20 Jan 20067 min read 173.8K   1K   94  
An article on nullable data readers for .NET 2.0 nullable types.
#region Using Directives

using System;

#endregion

namespace NullableReaders
{
    /// <summary>
    /// This interface defines the contract that a class must implement to read
    /// both non-null and nullable data.  The greatest benefit of this interface
    /// is that, since both NullableDataReader and NullableDataRowReader 
    /// implement it, this interface will allow these classes to be used 
    /// polymorphically.  In other words, if the consumer consumer need to 
    /// populate an object from both a IDataReader and/or a DataRow (from a
    /// DataSet) then they can just write 1 polymorphic method for this by
    /// programming against the INullableReader API rather than having to create
    /// two separate methods.
    /// Author: Steve Michelotti
    /// </summary>
    public interface INullableReader
    {

        #region Interface Methods

        bool GetBoolean(string name);
        Nullable<bool> GetNullableBoolean(string name);
        byte GetByte(string name);
        Nullable<byte> GetNullableByte(string name);
        char GetChar(string name);
        Nullable<char> GetNullableChar(string name);
        DateTime GetDateTime(string name);
        Nullable<DateTime> GetNullableDateTime(string name);
        decimal GetDecimal(string name);
        Nullable<Decimal> GetNullableDecimal(string name);
        double GetDouble(string name);
        Nullable<double> GetNullableDouble(string name);
        float GetFloat(string name);
        Nullable<float> GetNullableFloat(string name);
        Guid GetGuid(string name);
        Nullable<Guid> GetNullableGuid(string name);
        short GetInt16(string name);
        Nullable<short> GetNullableInt16(string name);
        int GetInt32(string name);
        Nullable<int> GetNullableInt32(string name);
        long GetInt64(string name);
        Nullable<long> GetNullableInt64(string name);
        string GetString(string name);
        string GetNullableString(string name);
        object GetValue(string name);
        bool IsDBNull(string name);

        #endregion

    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Steve Michelotti, MCSD, MCT is Principal Developer at e.magination in Baltimore - www.emagination.com.

Comments and Discussions