Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / WeakReferenceEnumerator.cs / 1305600 / WeakReferenceEnumerator.cs
using System; using System.Collections; using System.Windows; #if WINDOWS_BASE using MS.Internal.WindowsBase; #elif PRESENTATION_CORE using MS.Internal.PresentationCore; #elif PRESENTATIONFRAMEWORK using MS.Internal.PresentationFramework; #elif DRT using MS.Internal.Drt; #else #error Attempt to use FriendAccessAllowedAttribute from an unknown assembly. using MS.Internal.YourAssemblyName; #endif // Disable pragma warnings to enable PREsharp pragmas #pragma warning disable 1634, 1691 namespace MS.Internal { ////// This allows callers to "foreach" through a WeakReferenceList. /// Each weakreference is checked for liveness and "current" /// actually returns a strong reference to the current element. /// ////// Due to the way enumerators function, this enumerator often /// holds a cached strong reference to the "Current" element. /// This should not be a problem unless the caller stops enumerating /// before the end of the list AND holds the enumerator alive forever. /// [FriendAccessAllowed] internal struct WeakReferenceListEnumerator : IEnumerator { public WeakReferenceListEnumerator( ArrayList List) { _i = 0; _List = List; _StrongReference = null; } object IEnumerator.Current { get{ return Current; } } public object Current { get { if( null == _StrongReference ) { #pragma warning suppress 6503 throw new System.InvalidOperationException(SR.Get(SRID.Enumerator_VerifyContext)); } return _StrongReference; } } public bool MoveNext() { object obj=null; while( _i < _List.Count ) { WeakReference weakRef = (WeakReference) _List[ _i++ ]; obj = weakRef.Target; if(null != obj) break; } _StrongReference = obj; return (null != obj); } public void Reset() { _i = 0; _StrongReference = null; } int _i; ArrayList _List; object _StrongReference; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GlyphTypeface.cs
- WebScriptServiceHost.cs
- NumberFunctions.cs
- TextTreeTextElementNode.cs
- ConnectionPoint.cs
- selecteditemcollection.cs
- InkCanvasSelection.cs
- ListViewItem.cs
- TreeNodeMouseHoverEvent.cs
- PerformanceCountersElement.cs
- ControlParameter.cs
- TextDecorationUnitValidation.cs
- AccessDataSourceView.cs
- CultureSpecificStringDictionary.cs
- ProviderConnectionPoint.cs
- RuntimeEnvironment.cs
- ModelTreeEnumerator.cs
- WebPartPersonalization.cs
- TdsParserSafeHandles.cs
- CategoryEditor.cs
- RectangleGeometry.cs
- SmiEventSink_Default.cs
- DataBindingCollectionConverter.cs
- SafeMILHandle.cs
- ObjectResult.cs
- HandlerFactoryWrapper.cs
- DependencyPropertyConverter.cs
- ProfileGroupSettings.cs
- FilterException.cs
- RotateTransform.cs
- BitmapEffectDrawingContextState.cs
- DataBoundLiteralControl.cs
- EntityCollection.cs
- TextTreeText.cs
- DoubleAnimation.cs
- DLinqColumnProvider.cs
- Math.cs
- Dispatcher.cs
- RsaKeyGen.cs
- __ComObject.cs
- RoutingEndpointTrait.cs
- ParsedAttributeCollection.cs
- EntityDataSourceContextDisposingEventArgs.cs
- TextBreakpoint.cs
- Assembly.cs
- ReferentialConstraint.cs
- WindowInteractionStateTracker.cs
- CapabilitiesAssignment.cs
- LinqDataSourceSelectEventArgs.cs
- SystemIcons.cs
- Substitution.cs
- BaseCAMarshaler.cs
- TextStore.cs
- DataGridViewUtilities.cs
- FormsAuthentication.cs
- MemberProjectionIndex.cs
- AuthenticationModuleElementCollection.cs
- Menu.cs
- SpanIndex.cs
- Error.cs
- FilterQueryOptionExpression.cs
- Maps.cs
- SystemNetHelpers.cs
- SapiInterop.cs
- ReferencedType.cs
- QueryCursorEventArgs.cs
- sqlstateclientmanager.cs
- TextPointerBase.cs
- ModifiableIteratorCollection.cs
- XPathExpr.cs
- CryptoHelper.cs
- ListViewTableCell.cs
- HtmlTableRowCollection.cs
- ValidationSummary.cs
- DataBoundControl.cs
- StreamAsIStream.cs
- XmlSerializationReader.cs
- WebPartDisplayModeEventArgs.cs
- RequestQueryParser.cs
- LocalizedNameDescriptionPair.cs
- FormViewInsertedEventArgs.cs
- ApplicationManager.cs
- ThreadNeutralSemaphore.cs
- WindowsListViewGroupHelper.cs
- DesignTimeVisibleAttribute.cs
- COMException.cs
- XmlSchemaGroup.cs
- ItemChangedEventArgs.cs
- DetailsViewDeletedEventArgs.cs
- RankException.cs
- TextStore.cs
- ClassDataContract.cs
- HtmlHead.cs
- SettingsPropertyValue.cs
- CopyAttributesAction.cs
- MethodCallConverter.cs
- GuidelineCollection.cs
- XmlSignificantWhitespace.cs
- SmiSettersStream.cs
- XamlToRtfParser.cs