Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / ProviderBase / DbReferenceCollection.cs / 5 / DbReferenceCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.ProviderBase { using System; using System.Collections; using System.Diagnostics; internal abstract class DbReferenceCollection { #if ORACLE abstract public void Add(object value, int tag); abstract public void Notify(int message); abstract public void Remove(object value); #else private struct CollectionEntry { private int _tag; // information about the reference private WeakReference _weak; // the reference itself. public bool HasTarget { get { Debug.Assert((0 != _tag && null != _weak) || (null == _weak || !_weak.IsAlive), "0 tag with Target"); return ((0 != _tag) && null != _weak && _weak.IsAlive); } } public bool InUse { get { return (null != _weak); } } public int Tag { get { return _tag; } set { _tag = value; } } public object Target { get { if (0 != _tag) { return _weak.Target; } Debug.Assert(!_weak.IsAlive, "0 tag with Target"); return null; } set { if (null == _weak) { _weak = new WeakReference(value, false); } else { _weak.Target = value; } } } } private CollectionEntry[] _items; protected DbReferenceCollection() { _items = new CollectionEntry[5]; } abstract public void Add(object value, int tag); protected void AddItem(object value, int tag) { Debug.Assert(null != value && 0 != tag, "AddItem with null value or 0 tag"); CollectionEntry[] items = _items; for (int i = 0; i < items.Length; ++i) { if (!items[i].HasTarget) { items[i].Target = value; items[i].Tag = tag; Debug.Assert(items[i].HasTarget, "missing expected target"); return; } } int newlength = ((5 == items.Length) ? 15 : (items.Length + 15)); CollectionEntry[] jtems = new CollectionEntry[newlength]; for (int i = 0; i < items.Length; ++i) { jtems[i] = items[i]; } jtems[items.Length].Target = value; jtems[items.Length].Tag = tag; Debug.Assert(jtems[items.Length].HasTarget, "missing expected target"); _items = jtems; } internal IEnumerable Filter(int tag) { return new DbFilteredReferenceCollection (_items, tag); } public void Notify(int message) { CollectionEntry[] items = _items; for (int index = 0; index < items.Length; ++index) { if (items[index].InUse) { object value = items[index].Target; // checks tag & gets target if (null != value) { Debug.Assert(items[index].HasTarget, "missing expected target"); if (!NotifyItem(message, items[index].Tag, value)) { items[index].Tag = 0; items[index].Target = null; Debug.Assert(!items[index].HasTarget, "has unexpected target"); } } // else (0 == Tag) or !IsAlive } else { Debug.Assert(!items[index].HasTarget, "has unexpected target"); break; // we're done as soon as we find the first null in the list } } } abstract protected bool NotifyItem(int message, int tag, object value); public void Purge() { CollectionEntry[] items = _items; #if DEBUG for(int i = 0; i < items.Length; ++i) { Debug.Assert(!items[i].HasTarget, "unexpected target during purge"); } #endif if (100 < items.Length) { _items = new CollectionEntry[5]; // revert back to 5 items if we're really big... } } abstract public void Remove(object value); protected void RemoveItem(object value) { Debug.Assert(null != value, "RemoveItem with null"); CollectionEntry[] items = _items; for (int index = 0; index < items.Length; ++index) { if (items[index].InUse) { if (value == items[index].Target) { // checks tag & gets target items[index].Tag = 0; items[index].Target = null; Debug.Assert(!items[index].HasTarget, "has unexpected target"); break; } // else (0 == Tag) or !IsAlive or (value != Target) } else { break; // we're done as soon as we find the first null in the list } } } private struct DbFilteredReferenceCollection : IEnumerable { private readonly DbReferenceCollection.CollectionEntry[] _items; private readonly int _filterTag; internal DbFilteredReferenceCollection(DbReferenceCollection.CollectionEntry[] items, int filterTag) { _items = items; _filterTag = filterTag; } IEnumerator IEnumerable.GetEnumerator() { return new DbFilteredReferenceCollectionedEnumerator(_items, _filterTag); } private struct DbFilteredReferenceCollectionedEnumerator : IEnumerator { private readonly DbReferenceCollection.CollectionEntry[] _items; private readonly int _filterTag; private int _current; internal DbFilteredReferenceCollectionedEnumerator(DbReferenceCollection.CollectionEntry[] items, int filterTag) { _items = items; _filterTag = filterTag; _current = -1; } object IEnumerator.Current { get { return _items[_current].Target; } } bool IEnumerator.MoveNext() { while (++_current < _items.Length) { if (_items[_current].InUse) { if (_items[_current].Tag == _filterTag) { return true; } } else { break; } } return false; } void IEnumerator.Reset() { _current = -1; } } } #endif } } // 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.Diagnostics; internal abstract class DbReferenceCollection { #if ORACLE abstract public void Add(object value, int tag); abstract public void Notify(int message); abstract public void Remove(object value); #else private struct CollectionEntry { private int _tag; // information about the reference private WeakReference _weak; // the reference itself. public bool HasTarget { get { Debug.Assert((0 != _tag && null != _weak) || (null == _weak || !_weak.IsAlive), "0 tag with Target"); return ((0 != _tag) && null != _weak && _weak.IsAlive); } } public bool InUse { get { return (null != _weak); } } public int Tag { get { return _tag; } set { _tag = value; } } public object Target { get { if (0 != _tag) { return _weak.Target; } Debug.Assert(!_weak.IsAlive, "0 tag with Target"); return null; } set { if (null == _weak) { _weak = new WeakReference(value, false); } else { _weak.Target = value; } } } } private CollectionEntry[] _items; protected DbReferenceCollection() { _items = new CollectionEntry[5]; } abstract public void Add(object value, int tag); protected void AddItem(object value, int tag) { Debug.Assert(null != value && 0 != tag, "AddItem with null value or 0 tag"); CollectionEntry[] items = _items; for (int i = 0; i < items.Length; ++i) { if (!items[i].HasTarget) { items[i].Target = value; items[i].Tag = tag; Debug.Assert(items[i].HasTarget, "missing expected target"); return; } } int newlength = ((5 == items.Length) ? 15 : (items.Length + 15)); CollectionEntry[] jtems = new CollectionEntry[newlength]; for (int i = 0; i < items.Length; ++i) { jtems[i] = items[i]; } jtems[items.Length].Target = value; jtems[items.Length].Tag = tag; Debug.Assert(jtems[items.Length].HasTarget, "missing expected target"); _items = jtems; } internal IEnumerable Filter(int tag) { return new DbFilteredReferenceCollection (_items, tag); } public void Notify(int message) { CollectionEntry[] items = _items; for (int index = 0; index < items.Length; ++index) { if (items[index].InUse) { object value = items[index].Target; // checks tag & gets target if (null != value) { Debug.Assert(items[index].HasTarget, "missing expected target"); if (!NotifyItem(message, items[index].Tag, value)) { items[index].Tag = 0; items[index].Target = null; Debug.Assert(!items[index].HasTarget, "has unexpected target"); } } // else (0 == Tag) or !IsAlive } else { Debug.Assert(!items[index].HasTarget, "has unexpected target"); break; // we're done as soon as we find the first null in the list } } } abstract protected bool NotifyItem(int message, int tag, object value); public void Purge() { CollectionEntry[] items = _items; #if DEBUG for(int i = 0; i < items.Length; ++i) { Debug.Assert(!items[i].HasTarget, "unexpected target during purge"); } #endif if (100 < items.Length) { _items = new CollectionEntry[5]; // revert back to 5 items if we're really big... } } abstract public void Remove(object value); protected void RemoveItem(object value) { Debug.Assert(null != value, "RemoveItem with null"); CollectionEntry[] items = _items; for (int index = 0; index < items.Length; ++index) { if (items[index].InUse) { if (value == items[index].Target) { // checks tag & gets target items[index].Tag = 0; items[index].Target = null; Debug.Assert(!items[index].HasTarget, "has unexpected target"); break; } // else (0 == Tag) or !IsAlive or (value != Target) } else { break; // we're done as soon as we find the first null in the list } } } private struct DbFilteredReferenceCollection : IEnumerable { private readonly DbReferenceCollection.CollectionEntry[] _items; private readonly int _filterTag; internal DbFilteredReferenceCollection(DbReferenceCollection.CollectionEntry[] items, int filterTag) { _items = items; _filterTag = filterTag; } IEnumerator IEnumerable.GetEnumerator() { return new DbFilteredReferenceCollectionedEnumerator(_items, _filterTag); } private struct DbFilteredReferenceCollectionedEnumerator : IEnumerator { private readonly DbReferenceCollection.CollectionEntry[] _items; private readonly int _filterTag; private int _current; internal DbFilteredReferenceCollectionedEnumerator(DbReferenceCollection.CollectionEntry[] items, int filterTag) { _items = items; _filterTag = filterTag; _current = -1; } object IEnumerator.Current { get { return _items[_current].Target; } } bool IEnumerator.MoveNext() { while (++_current < _items.Length) { if (_items[_current].InUse) { if (_items[_current].Tag == _filterTag) { return true; } } else { break; } } return false; } void IEnumerator.Reset() { _current = -1; } } } #endif } } // 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
- EntityStoreSchemaFilterEntry.cs
- WindowsListViewGroupHelper.cs
- ResizeBehavior.cs
- XPathCompileException.cs
- InternalsVisibleToAttribute.cs
- MembershipSection.cs
- ScriptRef.cs
- ObjectQueryExecutionPlan.cs
- ArrayElementGridEntry.cs
- TrackingProfile.cs
- ColumnResizeAdorner.cs
- SizeLimitedCache.cs
- SQLMembershipProvider.cs
- XmlValidatingReader.cs
- TextContainerHelper.cs
- EdgeModeValidation.cs
- ManagedIStream.cs
- CultureTableRecord.cs
- StrokeCollection.cs
- CultureInfoConverter.cs
- URLIdentityPermission.cs
- HtmlControl.cs
- Vector3DAnimationUsingKeyFrames.cs
- Properties.cs
- CapabilitiesUse.cs
- PersonalizableTypeEntry.cs
- TypedCompletedAsyncResult.cs
- _PooledStream.cs
- FrameworkPropertyMetadata.cs
- XPathSelfQuery.cs
- QuaternionAnimation.cs
- QueryOutputWriter.cs
- CalendarData.cs
- EncryptedXml.cs
- HttpContextServiceHost.cs
- InkCanvas.cs
- BaseValidator.cs
- Rotation3D.cs
- ExpandedWrapper.cs
- BoundField.cs
- CellConstant.cs
- UInt64Storage.cs
- ListControl.cs
- XslAstAnalyzer.cs
- ParameterBuilder.cs
- DictionaryKeyPropertyAttribute.cs
- MultiTrigger.cs
- XslVisitor.cs
- WebMethodAttribute.cs
- RtfControls.cs
- SafeFileMapViewHandle.cs
- PersonalizationProviderCollection.cs
- DelayedRegex.cs
- Predicate.cs
- _OSSOCK.cs
- ZipIOLocalFileHeader.cs
- ProfessionalColorTable.cs
- SrgsDocument.cs
- ResXFileRef.cs
- ObjectDisposedException.cs
- DataGridViewAdvancedBorderStyle.cs
- UniqueConstraint.cs
- OrderByExpression.cs
- IgnoreFileBuildProvider.cs
- DoubleConverter.cs
- RequestCachePolicyConverter.cs
- MimeWriter.cs
- OdbcTransaction.cs
- Int32RectValueSerializer.cs
- IndexedString.cs
- CodeExpressionStatement.cs
- InfoCardKeyedHashAlgorithm.cs
- DataRecordInfo.cs
- SolidColorBrush.cs
- __ComObject.cs
- Visual3DCollection.cs
- PolicyImporterElement.cs
- CollectionViewSource.cs
- ToolStripPanel.cs
- StructuralCache.cs
- WebPartsPersonalizationAuthorization.cs
- CompoundFileStreamReference.cs
- FrameworkElementFactoryMarkupObject.cs
- IncomingWebRequestContext.cs
- TextBreakpoint.cs
- DbConnectionOptions.cs
- ToolStripDropDownButton.cs
- Vector3DAnimationUsingKeyFrames.cs
- Int32AnimationUsingKeyFrames.cs
- DetailsViewUpdateEventArgs.cs
- GridViewSelectEventArgs.cs
- EasingKeyFrames.cs
- MenuTracker.cs
- TimeSpanConverter.cs
- HierarchicalDataTemplate.cs
- MediaElement.cs
- IndentedWriter.cs
- StrokeSerializer.cs
- PropertyEmitterBase.cs
- ImageConverter.cs