Code:
/ 4.0 / 4.0 / 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. 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
- ActivityExecutionContext.cs
- ExpressionNormalizer.cs
- TaskResultSetter.cs
- RuntimeResourceSet.cs
- MediaContextNotificationWindow.cs
- ReflectionTypeLoadException.cs
- DataGridSortCommandEventArgs.cs
- EarlyBoundInfo.cs
- SplineKeyFrames.cs
- EntityDataSourceView.cs
- Script.cs
- Vector3DAnimation.cs
- MenuBindingsEditorForm.cs
- PlatformNotSupportedException.cs
- TextTreeUndoUnit.cs
- FileUtil.cs
- Html32TextWriter.cs
- PropertyKey.cs
- AppearanceEditorPart.cs
- Activity.cs
- Restrictions.cs
- SQLByte.cs
- SignedXml.cs
- FormatVersion.cs
- XPathDescendantIterator.cs
- PagedDataSource.cs
- ColorMatrix.cs
- CategoryAttribute.cs
- MembershipUser.cs
- WebHeaderCollection.cs
- PerformanceCounterPermissionEntry.cs
- SourceFileInfo.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- VirtualDirectoryMappingCollection.cs
- MasterPageCodeDomTreeGenerator.cs
- PathNode.cs
- smtpconnection.cs
- HtmlInputControl.cs
- OutputCacheSettingsSection.cs
- DataFieldConverter.cs
- ExceptionHandler.cs
- TextComposition.cs
- JournalEntryStack.cs
- TextBoxBase.cs
- SiteMapSection.cs
- Base64Encoder.cs
- SqlUserDefinedAggregateAttribute.cs
- RecipientInfo.cs
- processwaithandle.cs
- TagMapInfo.cs
- ToolStripDropDownItem.cs
- WorkflowViewService.cs
- DescendantQuery.cs
- HebrewCalendar.cs
- DataGridViewRowPrePaintEventArgs.cs
- OracleInfoMessageEventArgs.cs
- HiddenField.cs
- XmlWriterSettings.cs
- ContextMenuStrip.cs
- DocumentPageTextView.cs
- StylusDownEventArgs.cs
- WebColorConverter.cs
- Pen.cs
- DataListItemCollection.cs
- WrapPanel.cs
- CryptoApi.cs
- EntityException.cs
- RelatedPropertyManager.cs
- SmiXetterAccessMap.cs
- StringValidatorAttribute.cs
- UpdateTracker.cs
- VirtualPathUtility.cs
- CultureSpecificStringDictionary.cs
- DynamicActionMessageFilter.cs
- MsmqTransportSecurity.cs
- HashMembershipCondition.cs
- Rotation3DAnimation.cs
- StreamInfo.cs
- ToolStripDropDownMenu.cs
- FixedSchema.cs
- MatrixKeyFrameCollection.cs
- BinaryFormatterSinks.cs
- GorillaCodec.cs
- WindowsClaimSet.cs
- SQLRoleProvider.cs
- messageonlyhwndwrapper.cs
- XPathChildIterator.cs
- DataDocumentXPathNavigator.cs
- HotCommands.cs
- InvalidMessageContractException.cs
- AppDomainFactory.cs
- MenuScrollingVisibilityConverter.cs
- RegionInfo.cs
- Component.cs
- AsyncOperationContext.cs
- ExpressionBindingCollection.cs
- DataSourceView.cs
- BinaryObjectWriter.cs
- XamlWriter.cs
- PageThemeBuildProvider.cs