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
- BuildManager.cs
- GenericParameterDataContract.cs
- FormView.cs
- DispatchWrapper.cs
- WebColorConverter.cs
- CryptoProvider.cs
- SchemaContext.cs
- ListManagerBindingsCollection.cs
- FocusTracker.cs
- StickyNote.cs
- FixedBufferAttribute.cs
- UInt16Storage.cs
- TemplateControl.cs
- ToolStripComboBox.cs
- RefType.cs
- SqlDataSourceQuery.cs
- SessionIDManager.cs
- CollaborationHelperFunctions.cs
- Mouse.cs
- Image.cs
- EditModeSwitchButton.cs
- ApplicationFileCodeDomTreeGenerator.cs
- BrowserInteropHelper.cs
- FontInfo.cs
- SrgsSubset.cs
- SoapElementAttribute.cs
- BitFlagsGenerator.cs
- Char.cs
- UInt64Storage.cs
- OracleString.cs
- MarkerProperties.cs
- OperationPickerDialog.cs
- MediaElementAutomationPeer.cs
- DataGridViewSelectedCellCollection.cs
- RtfToXamlLexer.cs
- TimeoutException.cs
- ColumnResizeAdorner.cs
- PageAsyncTaskManager.cs
- PerspectiveCamera.cs
- TextServicesManager.cs
- CodeTypeParameter.cs
- Emitter.cs
- MenuTracker.cs
- PageBreakRecord.cs
- Identity.cs
- MenuItemAutomationPeer.cs
- ElementsClipboardData.cs
- OrderedDictionary.cs
- BindingValueChangedEventArgs.cs
- AssemblyHash.cs
- SqlCaseSimplifier.cs
- PeerApplicationLaunchInfo.cs
- TextDocumentView.cs
- WindowsIPAddress.cs
- DrawingCollection.cs
- XamlSerializationHelper.cs
- FlowPosition.cs
- DataServiceRequestException.cs
- CaseStatementProjectedSlot.cs
- XmlSignatureManifest.cs
- ZipPackagePart.cs
- ModelPropertyDescriptor.cs
- path.cs
- __FastResourceComparer.cs
- XmlQueryCardinality.cs
- AuthenticatingEventArgs.cs
- WeakReadOnlyCollection.cs
- RegistrationServices.cs
- TextTreeUndoUnit.cs
- ServiceChannelManager.cs
- SmtpNetworkElement.cs
- TransformProviderWrapper.cs
- DropDownList.cs
- FileBasedResourceGroveler.cs
- PersonalizationStateInfo.cs
- SrgsRuleRef.cs
- InterleavedZipPartStream.cs
- DisplayNameAttribute.cs
- EventLogInformation.cs
- DbParameterCollectionHelper.cs
- documentsequencetextview.cs
- SocketInformation.cs
- SerialPinChanges.cs
- FileUtil.cs
- CompiledAction.cs
- LinqDataView.cs
- ContextMenuStrip.cs
- WriteableOnDemandPackagePart.cs
- httpstaticobjectscollection.cs
- GetParentChain.cs
- SqlDuplicator.cs
- NamespaceDisplay.xaml.cs
- ColumnTypeConverter.cs
- Events.cs
- TemplateColumn.cs
- ScaleTransform3D.cs
- SmiMetaData.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- AttachedAnnotation.cs
- ActivityWithResult.cs