Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Shared / MS / Internal / WeakReferenceEnumerator.cs / 1 / 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
- CatchBlock.cs
- HttpPostedFileBase.cs
- DataPagerField.cs
- DaylightTime.cs
- SettingsPropertyIsReadOnlyException.cs
- FirewallWrapper.cs
- IArgumentProvider.cs
- AutomationPatternInfo.cs
- printdlgexmarshaler.cs
- HtmlWindow.cs
- TextChangedEventArgs.cs
- WCFModelStrings.Designer.cs
- FilterableAttribute.cs
- SqlDataReader.cs
- EntityWithKeyStrategy.cs
- PersistenceTypeAttribute.cs
- XmlNamespaceMapping.cs
- ComplusTypeValidator.cs
- ExpressionLink.cs
- CodeGotoStatement.cs
- GridViewDeletedEventArgs.cs
- DirectoryInfo.cs
- RectangleGeometry.cs
- TreeViewItemAutomationPeer.cs
- QilBinary.cs
- OfTypeExpression.cs
- TreeView.cs
- TargetConverter.cs
- ArraySortHelper.cs
- DesignerTransactionCloseEvent.cs
- HttpListenerContext.cs
- Sequence.cs
- WebPartDisplayModeEventArgs.cs
- InputLanguageManager.cs
- LinqDataSourceStatusEventArgs.cs
- GenericEnumerator.cs
- Int16Animation.cs
- StoryFragments.cs
- Console.cs
- Utils.cs
- IdentityNotMappedException.cs
- DecoderFallback.cs
- ItemAutomationPeer.cs
- Rect3D.cs
- SingleTagSectionHandler.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DataServiceException.cs
- ColumnBinding.cs
- PrivilegeNotHeldException.cs
- ExtensionElement.cs
- HostSecurityManager.cs
- CompositeDataBoundControl.cs
- IODescriptionAttribute.cs
- Privilege.cs
- NativeMethods.cs
- LoginView.cs
- FormatPage.cs
- CursorInteropHelper.cs
- CodeTypeDeclarationCollection.cs
- MultilineStringConverter.cs
- DrawToolTipEventArgs.cs
- MethodBody.cs
- SystemIPInterfaceStatistics.cs
- ToolStripDesignerUtils.cs
- BezierSegment.cs
- XmlConvert.cs
- LinqDataSourceDeleteEventArgs.cs
- WebConfigurationHostFileChange.cs
- SqlSelectStatement.cs
- NCryptSafeHandles.cs
- cookie.cs
- ParallelRangeManager.cs
- LinearQuaternionKeyFrame.cs
- VirtualPathUtility.cs
- WriteFileContext.cs
- MSG.cs
- DoubleAnimationUsingKeyFrames.cs
- Converter.cs
- StoreContentChangedEventArgs.cs
- LicenseContext.cs
- ConnectionStringSettings.cs
- webclient.cs
- Attributes.cs
- LassoSelectionBehavior.cs
- LogLogRecordEnumerator.cs
- TreeWalkHelper.cs
- ArgumentOutOfRangeException.cs
- ProcessModelInfo.cs
- LabelDesigner.cs
- SqlTypeConverter.cs
- HierarchicalDataSourceConverter.cs
- WebScriptClientGenerator.cs
- ValidationEventArgs.cs
- XPathItem.cs
- DataGridViewSortCompareEventArgs.cs
- ErrorWebPart.cs
- PeerName.cs
- __ComObject.cs
- DataGridViewCellStyle.cs
- BrowserDefinitionCollection.cs