Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / Common / FieldNameLookup.cs / 1 / FieldNameLookup.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.ProviderBase {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Text;
internal sealed class FieldNameLookup { // V1.2.3300, MDAC 69015, 71470
// hashtable stores the index into the _fieldNames, match via case-sensitive
private Hashtable _fieldNameLookup;
// original names for linear searches when exact matches fail
private string[] _fieldNames;
// if _defaultLocaleID is -1 then _compareInfo is initialized with InvariantCulture CompareInfo
// otherwise it is specified by the server? for the correct compare info
private CompareInfo _compareInfo;
private int _defaultLocaleID;
#if !ORACLE
public FieldNameLookup(string[] fieldNames, int defaultLocaleID) { // V1.2.3300
if (null == fieldNames) {
throw ADP.ArgumentNull("fieldNames");
}
_fieldNames = fieldNames;
_defaultLocaleID = defaultLocaleID;
}
#endif
public FieldNameLookup(IDataReader reader, int defaultLocaleID) { // V1.2.3300
int length = reader.FieldCount;
string[] fieldNames = new string[length];
for (int i = 0; i < length; ++i) {
fieldNames[i] = reader.GetName(i);
Debug.Assert(null != fieldNames[i], "MDAC 66681");
}
_fieldNames = fieldNames;
_defaultLocaleID = defaultLocaleID;
}
public int GetOrdinal(string fieldName) { // V1.2.3300
if (null == fieldName) {
throw ADP.ArgumentNull("fieldName");
}
int index = IndexOf(fieldName);
if (-1 == index) {
throw ADP.IndexOutOfRange(fieldName);
}
return index;
}
#if !ORACLE
public int IndexOfName(string fieldName) { // V1.2.3300
if (null == _fieldNameLookup) {
GenerateLookup();
}
// via case sensitive search, first match with lowest ordinal matches
object value = _fieldNameLookup[fieldName];
return ((null != value) ? (int) value : -1);
}
#endif
public int IndexOf(string fieldName) { // V1.2.3300
if (null == _fieldNameLookup) {
GenerateLookup();
}
int index;
object value = _fieldNameLookup[fieldName];
if (null != value) {
// via case sensitive search, first match with lowest ordinal matches
index = (int) value;
}
else {
// via case insensitive search, first match with lowest ordinal matches
index = LinearIndexOf(fieldName, CompareOptions.IgnoreCase);
if (-1 == index) {
// do the slow search now (kana, width insensitive comparison)
index = LinearIndexOf(fieldName, ADP.compareOptions);
}
}
return index;
}
private int LinearIndexOf(string fieldName, CompareOptions compareOptions) {
CompareInfo compareInfo = _compareInfo;
if (null == compareInfo) {
if (-1 != _defaultLocaleID) {
compareInfo = CompareInfo.GetCompareInfo(_defaultLocaleID);
}
if (null == compareInfo) {
compareInfo = CultureInfo.InvariantCulture.CompareInfo;
}
_compareInfo = compareInfo;
}
int length = _fieldNames.Length;
for (int i = 0; i < length; ++i) {
if (0 == compareInfo.Compare(fieldName, _fieldNames[i], compareOptions)) {
_fieldNameLookup[fieldName] = i; // add an exact match for the future
return i;
}
}
return -1;
}
// RTM common code for generating Hashtable from array of column names
private void GenerateLookup() {
int length = _fieldNames.Length;
Hashtable hash = new Hashtable(length);
// via case sensitive search, first match with lowest ordinal matches
for (int i = length-1; 0 <= i; --i) {
string fieldName = _fieldNames[i];
hash[fieldName] = i;
}
_fieldNameLookup = hash;
}
}
}
// 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.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Text;
internal sealed class FieldNameLookup { // V1.2.3300, MDAC 69015, 71470
// hashtable stores the index into the _fieldNames, match via case-sensitive
private Hashtable _fieldNameLookup;
// original names for linear searches when exact matches fail
private string[] _fieldNames;
// if _defaultLocaleID is -1 then _compareInfo is initialized with InvariantCulture CompareInfo
// otherwise it is specified by the server? for the correct compare info
private CompareInfo _compareInfo;
private int _defaultLocaleID;
#if !ORACLE
public FieldNameLookup(string[] fieldNames, int defaultLocaleID) { // V1.2.3300
if (null == fieldNames) {
throw ADP.ArgumentNull("fieldNames");
}
_fieldNames = fieldNames;
_defaultLocaleID = defaultLocaleID;
}
#endif
public FieldNameLookup(IDataReader reader, int defaultLocaleID) { // V1.2.3300
int length = reader.FieldCount;
string[] fieldNames = new string[length];
for (int i = 0; i < length; ++i) {
fieldNames[i] = reader.GetName(i);
Debug.Assert(null != fieldNames[i], "MDAC 66681");
}
_fieldNames = fieldNames;
_defaultLocaleID = defaultLocaleID;
}
public int GetOrdinal(string fieldName) { // V1.2.3300
if (null == fieldName) {
throw ADP.ArgumentNull("fieldName");
}
int index = IndexOf(fieldName);
if (-1 == index) {
throw ADP.IndexOutOfRange(fieldName);
}
return index;
}
#if !ORACLE
public int IndexOfName(string fieldName) { // V1.2.3300
if (null == _fieldNameLookup) {
GenerateLookup();
}
// via case sensitive search, first match with lowest ordinal matches
object value = _fieldNameLookup[fieldName];
return ((null != value) ? (int) value : -1);
}
#endif
public int IndexOf(string fieldName) { // V1.2.3300
if (null == _fieldNameLookup) {
GenerateLookup();
}
int index;
object value = _fieldNameLookup[fieldName];
if (null != value) {
// via case sensitive search, first match with lowest ordinal matches
index = (int) value;
}
else {
// via case insensitive search, first match with lowest ordinal matches
index = LinearIndexOf(fieldName, CompareOptions.IgnoreCase);
if (-1 == index) {
// do the slow search now (kana, width insensitive comparison)
index = LinearIndexOf(fieldName, ADP.compareOptions);
}
}
return index;
}
private int LinearIndexOf(string fieldName, CompareOptions compareOptions) {
CompareInfo compareInfo = _compareInfo;
if (null == compareInfo) {
if (-1 != _defaultLocaleID) {
compareInfo = CompareInfo.GetCompareInfo(_defaultLocaleID);
}
if (null == compareInfo) {
compareInfo = CultureInfo.InvariantCulture.CompareInfo;
}
_compareInfo = compareInfo;
}
int length = _fieldNames.Length;
for (int i = 0; i < length; ++i) {
if (0 == compareInfo.Compare(fieldName, _fieldNames[i], compareOptions)) {
_fieldNameLookup[fieldName] = i; // add an exact match for the future
return i;
}
}
return -1;
}
// RTM common code for generating Hashtable from array of column names
private void GenerateLookup() {
int length = _fieldNames.Length;
Hashtable hash = new Hashtable(length);
// via case sensitive search, first match with lowest ordinal matches
for (int i = length-1; 0 <= i; --i) {
string fieldName = _fieldNames[i];
hash[fieldName] = i;
}
_fieldNameLookup = hash;
}
}
}
// 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
- OleDbDataReader.cs
- SafeViewOfFileHandle.cs
- SchemaConstraints.cs
- BitmapSource.cs
- SqlTriggerContext.cs
- ChildTable.cs
- XmlSchemaComplexContentExtension.cs
- TypeLibConverter.cs
- TextEditorTyping.cs
- InternalsVisibleToAttribute.cs
- XamlGridLengthSerializer.cs
- WindowsContainer.cs
- CompilerGeneratedAttribute.cs
- ThreadSafeList.cs
- StreamGeometry.cs
- DocumentOrderComparer.cs
- GenericPrincipal.cs
- HeaderedContentControl.cs
- QuotedPairReader.cs
- StreamInfo.cs
- LinqDataSource.cs
- SimpleBitVector32.cs
- DataTableMappingCollection.cs
- ShaderRenderModeValidation.cs
- Model3D.cs
- MailMessageEventArgs.cs
- TabControlEvent.cs
- CalendarData.cs
- SessionStateSection.cs
- VariableValue.cs
- WebReferencesBuildProvider.cs
- TraceInternal.cs
- TableLayoutCellPaintEventArgs.cs
- Thickness.cs
- ActivityTrace.cs
- GraphicsContext.cs
- TraceInternal.cs
- LabelEditEvent.cs
- HttpDictionary.cs
- QualifierSet.cs
- DockProviderWrapper.cs
- DeploymentSection.cs
- recordstatefactory.cs
- AttributeXamlType.cs
- DBSchemaTable.cs
- QilName.cs
- SessionSwitchEventArgs.cs
- Argument.cs
- _OverlappedAsyncResult.cs
- TextServicesDisplayAttribute.cs
- ContainerControl.cs
- Enumerable.cs
- FileStream.cs
- TextSelectionProcessor.cs
- ObjectDataSourceMethodEventArgs.cs
- GrammarBuilderRuleRef.cs
- TextEncodedRawTextWriter.cs
- MultiPropertyDescriptorGridEntry.cs
- CheckBox.cs
- RNGCryptoServiceProvider.cs
- RankException.cs
- TemplateXamlTreeBuilder.cs
- SrgsDocument.cs
- UDPClient.cs
- RSAProtectedConfigurationProvider.cs
- BackgroundFormatInfo.cs
- ToolBarButton.cs
- WindowsAuthenticationModule.cs
- MemberRelationshipService.cs
- assemblycache.cs
- RefreshEventArgs.cs
- SystemIPInterfaceProperties.cs
- KeySpline.cs
- StreamInfo.cs
- ProgressBar.cs
- SmiMetaDataProperty.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- TextFormatterHost.cs
- SocketException.cs
- DefaultEvaluationContext.cs
- StringPropertyBuilder.cs
- CodeCatchClause.cs
- UserUseLicenseDictionaryLoader.cs
- ProfileModule.cs
- DocumentAutomationPeer.cs
- MouseBinding.cs
- ReferencedAssembly.cs
- AutoResetEvent.cs
- InstallerTypeAttribute.cs
- TreeView.cs
- SettingsAttributes.cs
- XMLSchema.cs
- ProtocolsConfigurationHandler.cs
- WorkflowTimerService.cs
- EntityDataSourceDataSelection.cs
- FlatButtonAppearance.cs
- WMIInterop.cs
- DataGridDesigner.cs
- Int64Storage.cs
- NamedElement.cs