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
- ModelVisual3D.cs
- VisualStyleTypesAndProperties.cs
- httpstaticobjectscollection.cs
- QilGenerator.cs
- ProbeDuplexCD1AsyncResult.cs
- RijndaelManagedTransform.cs
- SendSecurityHeaderElementContainer.cs
- ConvertEvent.cs
- PhysicalFontFamily.cs
- RectangleHotSpot.cs
- BitStack.cs
- CodeSnippetCompileUnit.cs
- WindowsClientCredential.cs
- ExpressionVisitorHelpers.cs
- CmsUtils.cs
- OneToOneMappingSerializer.cs
- RegisteredArrayDeclaration.cs
- DoubleLinkListEnumerator.cs
- DbConnectionFactory.cs
- NamespaceDecl.cs
- CanonicalFormWriter.cs
- ConnectionsZone.cs
- OletxEnlistment.cs
- FlatButtonAppearance.cs
- AuthorizationRule.cs
- EntityDataSourceContextCreatedEventArgs.cs
- UntypedNullExpression.cs
- _NestedMultipleAsyncResult.cs
- OAVariantLib.cs
- SizeConverter.cs
- RecommendedAsConfigurableAttribute.cs
- TempFiles.cs
- ConcurrentQueue.cs
- controlskin.cs
- TextTreeTextElementNode.cs
- ButtonBaseAdapter.cs
- ContentFilePart.cs
- HtmlContainerControl.cs
- DataGridCheckBoxColumn.cs
- ConfigurationManagerHelper.cs
- TableLayoutPanelBehavior.cs
- CanonicalXml.cs
- Vector3D.cs
- TextEndOfLine.cs
- CacheChildrenQuery.cs
- HttpApplication.cs
- BitmapEffectInput.cs
- ParameterToken.cs
- VisualBasicSettingsConverter.cs
- MobileResource.cs
- DataSourceProvider.cs
- CheckBoxPopupAdapter.cs
- Utils.cs
- StateWorkerRequest.cs
- ProtocolReflector.cs
- DataObjectMethodAttribute.cs
- XmlSerializerFactory.cs
- GridViewColumnCollectionChangedEventArgs.cs
- ListItemCollection.cs
- WinEventQueueItem.cs
- SecurityElement.cs
- XmlTextReader.cs
- WebPartManagerInternals.cs
- ParameterRetriever.cs
- MailAddressCollection.cs
- VideoDrawing.cs
- AlgoModule.cs
- _LocalDataStore.cs
- LinqDataSourceInsertEventArgs.cs
- XmlSchemaAppInfo.cs
- WindowHelperService.cs
- ListViewDeleteEventArgs.cs
- TagPrefixAttribute.cs
- PropertyGeneratedEventArgs.cs
- EventProviderWriter.cs
- BaseValidator.cs
- PixelFormatConverter.cs
- CorrelationRequestContext.cs
- ReadOnlyDictionary.cs
- WinInet.cs
- ObjectSet.cs
- CrossSiteScriptingValidation.cs
- IOThreadTimer.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- StaticTextPointer.cs
- ConstantProjectedSlot.cs
- StrongName.cs
- DoubleKeyFrameCollection.cs
- DotNetATv1WindowsLogEntryDeserializer.cs
- ImageCollectionEditor.cs
- RequestStatusBarUpdateEventArgs.cs
- RenderCapability.cs
- WriteableBitmap.cs
- RegexStringValidator.cs
- ViewManager.cs
- Membership.cs
- ServiceHostFactory.cs
- WorkflowApplicationCompletedException.cs
- HiddenFieldPageStatePersister.cs
- RepeaterItemCollection.cs