Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / FieldNameLookup.cs / 1305376 / FieldNameLookup.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { 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; public FieldNameLookup(System.Collections.ObjectModel.ReadOnlyCollectioncolumnNames, int defaultLocaleID) { int length = columnNames.Count; string[] fieldNames = new string[length]; for (int i = 0; i < length; ++i) { fieldNames[i] = columnNames[i]; Debug.Assert(null != fieldNames[i], "MDAC 66681"); } _fieldNames = fieldNames; _defaultLocaleID = defaultLocaleID; GenerateLookup(); } public FieldNameLookup(IDataRecord 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; } 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 { 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; public FieldNameLookup(System.Collections.ObjectModel.ReadOnlyCollectioncolumnNames, int defaultLocaleID) { int length = columnNames.Count; string[] fieldNames = new string[length]; for (int i = 0; i < length; ++i) { fieldNames[i] = columnNames[i]; Debug.Assert(null != fieldNames[i], "MDAC 66681"); } _fieldNames = fieldNames; _defaultLocaleID = defaultLocaleID; GenerateLookup(); } public FieldNameLookup(IDataRecord 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; } 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
- DocumentViewerAutomationPeer.cs
- DataGridViewCellConverter.cs
- SimpleApplicationHost.cs
- CaseInsensitiveHashCodeProvider.cs
- SqlCacheDependencyDatabase.cs
- GenerateScriptTypeAttribute.cs
- RtfToXamlLexer.cs
- InheritedPropertyChangedEventArgs.cs
- ThrowHelper.cs
- SharedConnectionWorkflowTransactionService.cs
- DataKey.cs
- XslTransform.cs
- Matrix3D.cs
- KeyFrames.cs
- VisualStyleRenderer.cs
- GridErrorDlg.cs
- TextRange.cs
- AssemblyInfo.cs
- StateManagedCollection.cs
- SafeRightsManagementSessionHandle.cs
- DragEventArgs.cs
- ItemsPresenter.cs
- RightsManagementInformation.cs
- TextRangeProviderWrapper.cs
- EntityExpressionVisitor.cs
- SQLBoolean.cs
- ScaleTransform.cs
- GetFileNameResult.cs
- UpdateTranslator.cs
- Attributes.cs
- SymmetricAlgorithm.cs
- StringHelper.cs
- QueryCacheKey.cs
- UInt32Converter.cs
- DataShape.cs
- CodeTypeMemberCollection.cs
- CharAnimationBase.cs
- FileDialog_Vista_Interop.cs
- WindowsScroll.cs
- FileChangesMonitor.cs
- PaintValueEventArgs.cs
- AssertFilter.cs
- AssemblyNameProxy.cs
- ActivityExecutionContext.cs
- StringAnimationUsingKeyFrames.cs
- VBCodeProvider.cs
- CustomExpression.cs
- UnauthorizedAccessException.cs
- AutomationPatternInfo.cs
- RepeatButton.cs
- SchemaImporterExtensionsSection.cs
- StylusPlugInCollection.cs
- ComplexPropertyEntry.cs
- ProxyWebPart.cs
- KerberosReceiverSecurityToken.cs
- UnauthorizedWebPart.cs
- CodeComment.cs
- GridItemPattern.cs
- TextBox.cs
- SecurityContextTokenCache.cs
- PerformanceCountersElement.cs
- ContextMenuAutomationPeer.cs
- NamespaceDisplayAutomationPeer.cs
- XmlEncApr2001.cs
- ContentDisposition.cs
- SqlFileStream.cs
- InternalSafeNativeMethods.cs
- WindowsGraphicsCacheManager.cs
- TabRenderer.cs
- StylusEditingBehavior.cs
- EventWaitHandle.cs
- HtmlTable.cs
- FileSystemWatcher.cs
- ExpressionNode.cs
- control.ime.cs
- WebPartPersonalization.cs
- Stack.cs
- RegexCaptureCollection.cs
- TraceContextRecord.cs
- ActivityCompletionCallbackWrapper.cs
- BrowserTree.cs
- ConnectionManagementElement.cs
- RegisteredHiddenField.cs
- SqlCommandBuilder.cs
- ToolTip.cs
- TabletDeviceInfo.cs
- ResourceDefaultValueAttribute.cs
- WinEventTracker.cs
- CodeStatement.cs
- ClientFormsIdentity.cs
- ButtonField.cs
- ProfessionalColorTable.cs
- HeaderedItemsControl.cs
- RectKeyFrameCollection.cs
- IIS7WorkerRequest.cs
- XmlWrappingWriter.cs
- SelectionProviderWrapper.cs
- MembershipUser.cs
- TypeDelegator.cs
- ScriptingScriptResourceHandlerSection.cs