1 //------------------------------------------------------------------------------
2 // <copyright file="dbenumerator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 namespace System
.Data
.Common
{
12 using System
.Collections
;
14 using System
.Data
.ProviderBase
;
15 using System
.Diagnostics
;
16 using System
.ComponentModel
;
18 public class DbEnumerator
: IEnumerator
{
20 internal IDataReader _reader
;
21 internal DbDataRecord _current
;
22 internal SchemaInfo
[] _schemaInfo
; // shared schema info among all the data records
23 internal PropertyDescriptorCollection _descriptors
; // cached property descriptors
24 private FieldNameLookup _fieldNameLookup
; // MDAC 69015
25 private bool closeReader
;
27 // users must get enumerators off of the datareader interfaces
28 public DbEnumerator(IDataReader reader
) {
30 throw ADP
.ArgumentNull("reader");
35 public DbEnumerator(IDataReader reader
, bool closeReader
) { // MDAC 68670
37 throw ADP
.ArgumentNull("reader");
40 this.closeReader
= closeReader
;
43 public DbEnumerator(DbDataReader reader
)
44 : this((IDataReader
)reader
) {
47 public DbEnumerator(DbDataReader reader
, bool closeReader
)
48 : this((IDataReader
)reader
, closeReader
) {
51 public object Current
{
57 public bool MoveNext() {
59 if (null == _schemaInfo
) {
63 Debug
.Assert(null != _schemaInfo
&& null != _descriptors
, "unable to build schema information!");
67 // setup our current record
68 object[] values
= new object[_schemaInfo
.Length
];
69 _reader
.GetValues(values
); // this.GetValues()
70 _current
= new DataRecordInternal(_schemaInfo
, values
, _descriptors
, _fieldNameLookup
); // this.NewRecord()
79 [ EditorBrowsableAttribute(EditorBrowsableState
.Never
) ] // MDAC 69508
81 throw ADP
.NotSupported();
84 private void BuildSchemaInfo() {
85 int count
= _reader
.FieldCount
;
86 string[] fieldnames
= new string[count
];
87 for (int i
= 0; i
< count
; ++i
) {
88 fieldnames
[i
] = _reader
.GetName(i
);
90 ADP
.BuildSchemaTableInfoTableNames(fieldnames
); // MDAC 71401
92 SchemaInfo
[] si
= new SchemaInfo
[count
];
93 PropertyDescriptor
[] props
= new PropertyDescriptor
[_reader
.FieldCount
];
94 for (int i
= 0; i
< si
.Length
; i
++) {
95 SchemaInfo s
= new SchemaInfo();
96 s
.name
= _reader
.GetName(i
);
97 s
.type
= _reader
.GetFieldType(i
);
98 s
.typeName
= _reader
.GetDataTypeName(i
);
99 props
[i
] = new DbColumnDescriptor(i
, fieldnames
[i
], s
.type
);
104 _fieldNameLookup
= new FieldNameLookup(_reader
, -1); // MDAC 71470
105 _descriptors
= new PropertyDescriptorCollection(props
);
108 sealed private class DbColumnDescriptor
: PropertyDescriptor
{
112 internal DbColumnDescriptor(int ordinal
, string name
, Type type
)
118 public override Type ComponentType
{
120 return typeof(IDataRecord
);
124 public override bool IsReadOnly
{
130 public override Type PropertyType
{
136 public override bool CanResetValue(object component
) {
140 public override object GetValue(object component
) {
141 return ((IDataRecord
)component
)[_ordinal
];
144 public override void ResetValue(object component
) {
145 throw ADP
.NotSupported();
148 public override void SetValue(object component
, object value) {
149 throw ADP
.NotSupported();
152 public override bool ShouldSerializeValue(object component
) {