Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / Common / dbenumerator.cs / 1305376 / dbenumerator.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common {
using System;
using System.Collections;
using System.Data;
using System.Data.ProviderBase;
using System.Diagnostics;
using System.ComponentModel;
public class DbEnumerator : IEnumerator {
internal IDataReader _reader;
internal IDataRecord _current;
internal SchemaInfo[] _schemaInfo; // shared schema info among all the data records
internal PropertyDescriptorCollection _descriptors; // cached property descriptors
private FieldNameLookup _fieldNameLookup; // MDAC 69015
private bool closeReader;
// users must get enumerators off of the datareader interfaces
public DbEnumerator(IDataReader reader) {
if (null == reader) {
throw ADP.ArgumentNull("reader");
}
_reader = reader;
}
public DbEnumerator(IDataReader reader, bool closeReader) { // MDAC 68670
if (null == reader) {
throw ADP.ArgumentNull("reader");
}
_reader = reader;
this.closeReader = closeReader;
}
public object Current {
get {
return _current;
}
}
/*public IDataRecord Current {
get {
return _current;
}
}*/
/*
virtual internal IDataRecord NewRecord(SchemaInfo[] si, object[] values, PropertyDescriptorCollection descriptors) {
return new DbDataRecord(si, values, descriptors);
}
virtual internal void GetValues(object[] values) {
_reader.GetValues(values);
}
*/
public bool MoveNext() {
if (null == _schemaInfo) {
BuildSchemaInfo();
}
Debug.Assert(null != _schemaInfo && null != _descriptors, "unable to build schema information!");
_current = null;
if (_reader.Read()) {
// setup our current record
object[] values = new object[_schemaInfo.Length];
_reader.GetValues(values); // this.GetValues()
_current = new DataRecordInternal(_schemaInfo, values, _descriptors, _fieldNameLookup); // this.NewRecord()
return true;
}
if (closeReader) {
_reader.Close();
}
return false;
}
[ EditorBrowsableAttribute(EditorBrowsableState.Never) ] // MDAC 69508
public void Reset() {
throw ADP.NotSupported();
}
private void BuildSchemaInfo() {
int count = _reader.FieldCount;
string[] fieldnames = new string[count];
for (int i = 0; i < count; ++i) {
fieldnames[i] = _reader.GetName(i);
}
ADP.BuildSchemaTableInfoTableNames(fieldnames); // MDAC 71401
SchemaInfo[] si = new SchemaInfo[count];
PropertyDescriptor[] props = new PropertyDescriptor[_reader.FieldCount];
for (int i = 0; i < si.Length; i++) {
SchemaInfo s = new SchemaInfo();
s.name = _reader.GetName(i);
s.type = _reader.GetFieldType(i);
s.typeName = _reader.GetDataTypeName(i);
props[i] = new DbColumnDescriptor(i, fieldnames[i], s.type);
si[i] = s;
}
_schemaInfo = si;
_fieldNameLookup = new FieldNameLookup(_reader, -1); // MDAC 71470
_descriptors = new PropertyDescriptorCollection(props);
}
sealed private class DbColumnDescriptor : PropertyDescriptor {
int _ordinal;
Type _type;
internal DbColumnDescriptor(int ordinal, string name, Type type)
: base(name, null) {
_ordinal = ordinal;
_type = type;
}
public override Type ComponentType {
get {
return typeof(IDataRecord);
}
}
public override bool IsReadOnly {
get {
return true;
}
}
public override Type PropertyType {
get {
return _type;
}
}
public override bool CanResetValue(object component) {
return false;
}
public override object GetValue(object component) {
return ((IDataRecord)component)[_ordinal];
}
public override void ResetValue(object component) {
throw ADP.NotSupported();
}
public override void SetValue(object component, object value) {
throw ADP.NotSupported();
}
public override bool ShouldSerializeValue(object component) {
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common {
using System;
using System.Collections;
using System.Data;
using System.Data.ProviderBase;
using System.Diagnostics;
using System.ComponentModel;
public class DbEnumerator : IEnumerator {
internal IDataReader _reader;
internal IDataRecord _current;
internal SchemaInfo[] _schemaInfo; // shared schema info among all the data records
internal PropertyDescriptorCollection _descriptors; // cached property descriptors
private FieldNameLookup _fieldNameLookup; // MDAC 69015
private bool closeReader;
// users must get enumerators off of the datareader interfaces
public DbEnumerator(IDataReader reader) {
if (null == reader) {
throw ADP.ArgumentNull("reader");
}
_reader = reader;
}
public DbEnumerator(IDataReader reader, bool closeReader) { // MDAC 68670
if (null == reader) {
throw ADP.ArgumentNull("reader");
}
_reader = reader;
this.closeReader = closeReader;
}
public object Current {
get {
return _current;
}
}
/*public IDataRecord Current {
get {
return _current;
}
}*/
/*
virtual internal IDataRecord NewRecord(SchemaInfo[] si, object[] values, PropertyDescriptorCollection descriptors) {
return new DbDataRecord(si, values, descriptors);
}
virtual internal void GetValues(object[] values) {
_reader.GetValues(values);
}
*/
public bool MoveNext() {
if (null == _schemaInfo) {
BuildSchemaInfo();
}
Debug.Assert(null != _schemaInfo && null != _descriptors, "unable to build schema information!");
_current = null;
if (_reader.Read()) {
// setup our current record
object[] values = new object[_schemaInfo.Length];
_reader.GetValues(values); // this.GetValues()
_current = new DataRecordInternal(_schemaInfo, values, _descriptors, _fieldNameLookup); // this.NewRecord()
return true;
}
if (closeReader) {
_reader.Close();
}
return false;
}
[ EditorBrowsableAttribute(EditorBrowsableState.Never) ] // MDAC 69508
public void Reset() {
throw ADP.NotSupported();
}
private void BuildSchemaInfo() {
int count = _reader.FieldCount;
string[] fieldnames = new string[count];
for (int i = 0; i < count; ++i) {
fieldnames[i] = _reader.GetName(i);
}
ADP.BuildSchemaTableInfoTableNames(fieldnames); // MDAC 71401
SchemaInfo[] si = new SchemaInfo[count];
PropertyDescriptor[] props = new PropertyDescriptor[_reader.FieldCount];
for (int i = 0; i < si.Length; i++) {
SchemaInfo s = new SchemaInfo();
s.name = _reader.GetName(i);
s.type = _reader.GetFieldType(i);
s.typeName = _reader.GetDataTypeName(i);
props[i] = new DbColumnDescriptor(i, fieldnames[i], s.type);
si[i] = s;
}
_schemaInfo = si;
_fieldNameLookup = new FieldNameLookup(_reader, -1); // MDAC 71470
_descriptors = new PropertyDescriptorCollection(props);
}
sealed private class DbColumnDescriptor : PropertyDescriptor {
int _ordinal;
Type _type;
internal DbColumnDescriptor(int ordinal, string name, Type type)
: base(name, null) {
_ordinal = ordinal;
_type = type;
}
public override Type ComponentType {
get {
return typeof(IDataRecord);
}
}
public override bool IsReadOnly {
get {
return true;
}
}
public override Type PropertyType {
get {
return _type;
}
}
public override bool CanResetValue(object component) {
return false;
}
public override object GetValue(object component) {
return ((IDataRecord)component)[_ordinal];
}
public override void ResetValue(object component) {
throw ADP.NotSupported();
}
public override void SetValue(object component, object value) {
throw ADP.NotSupported();
}
public override bool ShouldSerializeValue(object component) {
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListViewSortEventArgs.cs
- PolygonHotSpot.cs
- ContextStaticAttribute.cs
- RunClient.cs
- ToolStripItemImageRenderEventArgs.cs
- ActiveXContainer.cs
- EmptyQuery.cs
- SqlClientPermission.cs
- ResXResourceWriter.cs
- QueryOpeningEnumerator.cs
- IDQuery.cs
- CodePrimitiveExpression.cs
- HMACMD5.cs
- SafeFindHandle.cs
- ThemeInfoAttribute.cs
- MethodBuilderInstantiation.cs
- TemplateControlCodeDomTreeGenerator.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- KnownIds.cs
- XmlSchemaInfo.cs
- PrintEvent.cs
- SQLInt16.cs
- PropertyValue.cs
- SqlMethodCallConverter.cs
- PointAnimationUsingPath.cs
- WebPartDeleteVerb.cs
- FileDataSourceCache.cs
- InternalControlCollection.cs
- ThreadInterruptedException.cs
- Base64Encoder.cs
- LightweightCodeGenerator.cs
- AttachmentCollection.cs
- RegionInfo.cs
- FormCollection.cs
- MemberRelationshipService.cs
- DbProviderSpecificTypePropertyAttribute.cs
- SoapExtensionImporter.cs
- ToolStripControlHost.cs
- TextWriterTraceListener.cs
- OdbcHandle.cs
- AsymmetricSignatureFormatter.cs
- JumpTask.cs
- AtomMaterializer.cs
- ObjectViewListener.cs
- SerialErrors.cs
- SqlCommandSet.cs
- SqlClientFactory.cs
- Console.cs
- RenamedEventArgs.cs
- Update.cs
- BlurBitmapEffect.cs
- XmlSchemaImport.cs
- AdapterUtil.cs
- StringUtil.cs
- XmlDataProvider.cs
- ArrayWithOffset.cs
- SlipBehavior.cs
- HttpListenerTimeoutManager.cs
- XmlBinaryReader.cs
- ControlCachePolicy.cs
- SiteMap.cs
- Thread.cs
- StrongNameKeyPair.cs
- PartialCachingAttribute.cs
- HealthMonitoringSectionHelper.cs
- Icon.cs
- SafeNativeMethodsCLR.cs
- StructuredTypeEmitter.cs
- HwndAppCommandInputProvider.cs
- StaticSiteMapProvider.cs
- StructuredType.cs
- SettingsPropertyNotFoundException.cs
- ping.cs
- Message.cs
- TextRangeEditLists.cs
- X509ScopedServiceCertificateElement.cs
- ListBoxItemAutomationPeer.cs
- ConfigXmlAttribute.cs
- RuleConditionDialog.Designer.cs
- Converter.cs
- IMembershipProvider.cs
- AutomationProperty.cs
- NonDualMessageSecurityOverHttp.cs
- BackStopAuthenticationModule.cs
- CompressedStack.cs
- IncrementalHitTester.cs
- SubMenuStyleCollection.cs
- RowToParametersTransformer.cs
- TagPrefixAttribute.cs
- PropertyFilterAttribute.cs
- DesignerResources.cs
- WebPartVerbsEventArgs.cs
- Camera.cs
- BrowsableAttribute.cs
- AssociationSetMetadata.cs
- SignerInfo.cs
- TrustLevelCollection.cs
- NavigateUrlConverter.cs
- filewebrequest.cs
- InternalTypeHelper.cs