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
- ExtenderControl.cs
- StrongNameIdentityPermission.cs
- EventProperty.cs
- SystemIPAddressInformation.cs
- SimpleRecyclingCache.cs
- _ListenerAsyncResult.cs
- LogicalChannel.cs
- UserPrincipalNameElement.cs
- XmlAttributes.cs
- FastEncoderWindow.cs
- Speller.cs
- RepeaterItemCollection.cs
- DiscoveryClientElement.cs
- externdll.cs
- NullableBoolConverter.cs
- DisplayInformation.cs
- InputScope.cs
- DataGridViewRowHeaderCell.cs
- ManagedIStream.cs
- ImageInfo.cs
- Int16Converter.cs
- FixedSOMGroup.cs
- UIElementParagraph.cs
- WindowsRichEditRange.cs
- NamespaceQuery.cs
- DeobfuscatingStream.cs
- TrustManager.cs
- TypographyProperties.cs
- EventProvider.cs
- Socket.cs
- ClientReliableChannelBinder.cs
- WindowsUpDown.cs
- FixedSOMPageConstructor.cs
- Int32EqualityComparer.cs
- ImageFormatConverter.cs
- MatrixStack.cs
- XmlDataImplementation.cs
- FixUp.cs
- ApplicationDirectoryMembershipCondition.cs
- InvokeFunc.cs
- QilScopedVisitor.cs
- AudioSignalProblemOccurredEventArgs.cs
- InstanceDescriptor.cs
- ExpressionBindings.cs
- SimpleMailWebEventProvider.cs
- PeerApplicationLaunchInfo.cs
- RandomNumberGenerator.cs
- securitycriticaldataformultiplegetandset.cs
- NativeBuffer.cs
- DispatcherEventArgs.cs
- ThicknessConverter.cs
- PlainXmlWriter.cs
- ViewCellRelation.cs
- DataGridViewCellValidatingEventArgs.cs
- OpenTypeLayout.cs
- Console.cs
- SqlNotificationRequest.cs
- KeyEvent.cs
- XmlProcessingInstruction.cs
- DesignTimeTemplateParser.cs
- PersonalizationAdministration.cs
- ReliableSessionElement.cs
- SHA256Managed.cs
- TakeOrSkipQueryOperator.cs
- SQLConvert.cs
- TemplatedMailWebEventProvider.cs
- ProfilePropertySettingsCollection.cs
- SystemDropShadowChrome.cs
- TreePrinter.cs
- QilReplaceVisitor.cs
- SqlClientPermission.cs
- SafeUserTokenHandle.cs
- ViewManager.cs
- WebPartChrome.cs
- TCPClient.cs
- UidManager.cs
- EntityContainer.cs
- ZipArchive.cs
- AncestorChangedEventArgs.cs
- SecurityBindingElement.cs
- LineServicesCallbacks.cs
- DateTimeConverter.cs
- AssertUtility.cs
- PriorityQueue.cs
- UnconditionalPolicy.cs
- XPathSelectionIterator.cs
- FontCacheLogic.cs
- FrameworkPropertyMetadata.cs
- CompModSwitches.cs
- XmlWrappingReader.cs
- DataStorage.cs
- Geometry3D.cs
- CheckedListBox.cs
- ConsoleTraceListener.cs
- WindowsHyperlink.cs
- smtpconnection.cs
- OutputCacheProfileCollection.cs
- KnownTypesProvider.cs
- XmlChoiceIdentifierAttribute.cs
- TransformValueSerializer.cs