DataReaderContainer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / ProviderBase / DataReaderContainer.cs / 1 / DataReaderContainer.cs

                            //------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
namespace System.Data.ProviderBase { 

    using System; 
    using System.Data;
    using System.Data.Common;
    using System.Diagnostics;
 
    internal abstract class DataReaderContainer {
 
        protected readonly IDataReader _dataReader; 
        protected int _fieldCount;
 
        static internal DataReaderContainer Create(IDataReader dataReader, bool returnProviderSpecificTypes) {
            if (returnProviderSpecificTypes) {
                DbDataReader providerSpecificDataReader = (dataReader as DbDataReader);
                if (null != providerSpecificDataReader) { 
                    return new ProviderSpecificDataReader(dataReader, providerSpecificDataReader);
                } 
            } 
            return new CommonLanguageSubsetDataReader(dataReader);
        } 

        protected DataReaderContainer(IDataReader dataReader) {
            Debug.Assert(null != dataReader, "null dataReader");
            _dataReader = dataReader; 
        }
 
        internal int FieldCount { 
            get {
                return _fieldCount; 
            }
        }

        internal abstract bool ReturnProviderSpecificTypes { get; } 
        protected abstract int VisibleFieldCount { get; }
 
        internal abstract Type GetFieldType(int ordinal); 
        internal abstract object GetValue(int ordinal);
        internal abstract int GetValues(object[] values); 

        internal string GetName(int ordinal) {
            string fieldName = _dataReader.GetName(ordinal);
            Debug.Assert(null != fieldName, "null GetName"); 
            return ((null != fieldName) ? fieldName : "");
        } 
        internal DataTable GetSchemaTable() { 
            return _dataReader.GetSchemaTable();
        } 
        internal bool NextResult() {
            _fieldCount = 0;
            if (_dataReader.NextResult()) {
                _fieldCount = VisibleFieldCount; 
                return true;
            } 
            return false; 
        }
        internal bool Read() { 
            return _dataReader.Read();
        }

        private sealed class ProviderSpecificDataReader : DataReaderContainer { 
            private DbDataReader _providerSpecificDataReader;
 
            internal ProviderSpecificDataReader(IDataReader dataReader, DbDataReader dbDataReader) : base(dataReader) { 
                Debug.Assert(null != dataReader, "null dbDataReader");
                _providerSpecificDataReader = dbDataReader; 
                _fieldCount = VisibleFieldCount;
            }

            internal override bool ReturnProviderSpecificTypes { 
                get {
                    return true; 
                } 
            }
            protected override int VisibleFieldCount { 
                get {
                    int fieldCount = _providerSpecificDataReader.VisibleFieldCount;
                    Debug.Assert(0 <= fieldCount, "negative FieldCount");
                    return ((0 <= fieldCount) ? fieldCount : 0); 
                }
            } 
 
            internal override Type GetFieldType(int ordinal) {
                Type fieldType = _providerSpecificDataReader.GetProviderSpecificFieldType(ordinal); 
                Debug.Assert(null != fieldType, "null FieldType");
                return fieldType;
            }
            internal override object GetValue(int ordinal) { 
                return _providerSpecificDataReader.GetProviderSpecificValue(ordinal);
            } 
            internal override int GetValues(object[] values) { 
                return _providerSpecificDataReader.GetProviderSpecificValues(values);
            } 
        }

        private sealed class CommonLanguageSubsetDataReader : DataReaderContainer {
 
            internal CommonLanguageSubsetDataReader(IDataReader dataReader ) : base(dataReader) {
                _fieldCount = VisibleFieldCount; 
            } 

            internal override bool ReturnProviderSpecificTypes { 
                get {
                    return false;
                }
            } 
            protected override int VisibleFieldCount {
                get { 
                    int fieldCount = _dataReader.FieldCount; 
                    Debug.Assert(0 <= fieldCount, "negative FieldCount");
                    return ((0 <= fieldCount) ? fieldCount : 0); 
                }
            }

            internal override Type GetFieldType(int ordinal) { 
                return _dataReader.GetFieldType(ordinal);
            } 
            internal override object GetValue(int ordinal) { 
                return _dataReader.GetValue(ordinal);
            } 
            internal override int GetValues(object[] values) {
                return _dataReader.GetValues(values);
            }
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
namespace System.Data.ProviderBase { 

    using System; 
    using System.Data;
    using System.Data.Common;
    using System.Diagnostics;
 
    internal abstract class DataReaderContainer {
 
        protected readonly IDataReader _dataReader; 
        protected int _fieldCount;
 
        static internal DataReaderContainer Create(IDataReader dataReader, bool returnProviderSpecificTypes) {
            if (returnProviderSpecificTypes) {
                DbDataReader providerSpecificDataReader = (dataReader as DbDataReader);
                if (null != providerSpecificDataReader) { 
                    return new ProviderSpecificDataReader(dataReader, providerSpecificDataReader);
                } 
            } 
            return new CommonLanguageSubsetDataReader(dataReader);
        } 

        protected DataReaderContainer(IDataReader dataReader) {
            Debug.Assert(null != dataReader, "null dataReader");
            _dataReader = dataReader; 
        }
 
        internal int FieldCount { 
            get {
                return _fieldCount; 
            }
        }

        internal abstract bool ReturnProviderSpecificTypes { get; } 
        protected abstract int VisibleFieldCount { get; }
 
        internal abstract Type GetFieldType(int ordinal); 
        internal abstract object GetValue(int ordinal);
        internal abstract int GetValues(object[] values); 

        internal string GetName(int ordinal) {
            string fieldName = _dataReader.GetName(ordinal);
            Debug.Assert(null != fieldName, "null GetName"); 
            return ((null != fieldName) ? fieldName : "");
        } 
        internal DataTable GetSchemaTable() { 
            return _dataReader.GetSchemaTable();
        } 
        internal bool NextResult() {
            _fieldCount = 0;
            if (_dataReader.NextResult()) {
                _fieldCount = VisibleFieldCount; 
                return true;
            } 
            return false; 
        }
        internal bool Read() { 
            return _dataReader.Read();
        }

        private sealed class ProviderSpecificDataReader : DataReaderContainer { 
            private DbDataReader _providerSpecificDataReader;
 
            internal ProviderSpecificDataReader(IDataReader dataReader, DbDataReader dbDataReader) : base(dataReader) { 
                Debug.Assert(null != dataReader, "null dbDataReader");
                _providerSpecificDataReader = dbDataReader; 
                _fieldCount = VisibleFieldCount;
            }

            internal override bool ReturnProviderSpecificTypes { 
                get {
                    return true; 
                } 
            }
            protected override int VisibleFieldCount { 
                get {
                    int fieldCount = _providerSpecificDataReader.VisibleFieldCount;
                    Debug.Assert(0 <= fieldCount, "negative FieldCount");
                    return ((0 <= fieldCount) ? fieldCount : 0); 
                }
            } 
 
            internal override Type GetFieldType(int ordinal) {
                Type fieldType = _providerSpecificDataReader.GetProviderSpecificFieldType(ordinal); 
                Debug.Assert(null != fieldType, "null FieldType");
                return fieldType;
            }
            internal override object GetValue(int ordinal) { 
                return _providerSpecificDataReader.GetProviderSpecificValue(ordinal);
            } 
            internal override int GetValues(object[] values) { 
                return _providerSpecificDataReader.GetProviderSpecificValues(values);
            } 
        }

        private sealed class CommonLanguageSubsetDataReader : DataReaderContainer {
 
            internal CommonLanguageSubsetDataReader(IDataReader dataReader ) : base(dataReader) {
                _fieldCount = VisibleFieldCount; 
            } 

            internal override bool ReturnProviderSpecificTypes { 
                get {
                    return false;
                }
            } 
            protected override int VisibleFieldCount {
                get { 
                    int fieldCount = _dataReader.FieldCount; 
                    Debug.Assert(0 <= fieldCount, "negative FieldCount");
                    return ((0 <= fieldCount) ? fieldCount : 0); 
                }
            }

            internal override Type GetFieldType(int ordinal) { 
                return _dataReader.GetFieldType(ordinal);
            } 
            internal override object GetValue(int ordinal) { 
                return _dataReader.GetValue(ordinal);
            } 
            internal override int GetValues(object[] values) {
                return _dataReader.GetValues(values);
            }
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK