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
- GrammarBuilder.cs
- PreProcessInputEventArgs.cs
- Brush.cs
- Schema.cs
- InputDevice.cs
- CompilerCollection.cs
- NamedElement.cs
- ObjectDataSourceFilteringEventArgs.cs
- WebPartMenuStyle.cs
- codemethodreferenceexpression.cs
- HandlerBase.cs
- RowVisual.cs
- SettingsPropertyIsReadOnlyException.cs
- ProgressBarBrushConverter.cs
- Unit.cs
- SiteMapDataSource.cs
- TextServicesCompartmentContext.cs
- Positioning.cs
- COM2DataTypeToManagedDataTypeConverter.cs
- CommandPlan.cs
- ThumbAutomationPeer.cs
- DefaultValueAttribute.cs
- COMException.cs
- FileIOPermission.cs
- sqlpipe.cs
- CanonicalXml.cs
- SqlFlattener.cs
- ObjectCloneHelper.cs
- HtmlInputSubmit.cs
- NameValuePermission.cs
- EntityDataSourceEntityTypeFilterItem.cs
- StringConverter.cs
- HelpKeywordAttribute.cs
- OutputCacheProfile.cs
- HtmlImage.cs
- CheckBoxBaseAdapter.cs
- StorageMappingItemCollection.cs
- StrongName.cs
- ScriptBehaviorDescriptor.cs
- XmlRootAttribute.cs
- ToolBarDesigner.cs
- Visual.cs
- RequestQueryProcessor.cs
- CmsInterop.cs
- ProcessHostMapPath.cs
- MediaContextNotificationWindow.cs
- MeasureItemEvent.cs
- JsonDataContract.cs
- XamlHttpHandlerFactory.cs
- TableRow.cs
- EventHandlingScope.cs
- ProgressBarHighlightConverter.cs
- BackgroundFormatInfo.cs
- TransactionFlowProperty.cs
- MILUtilities.cs
- TemplateBindingExtensionConverter.cs
- DesignTimeDataBinding.cs
- SamlDoNotCacheCondition.cs
- ClassDataContract.cs
- PropertyAccessVisitor.cs
- XamlWrappingReader.cs
- CodeSnippetStatement.cs
- UidManager.cs
- DWriteFactory.cs
- ReceiveCompletedEventArgs.cs
- TemplatePagerField.cs
- WebPartDescriptionCollection.cs
- StylusPointPropertyInfo.cs
- WebPartConnection.cs
- RefreshInfo.cs
- BinHexEncoder.cs
- LOSFormatter.cs
- BackgroundWorker.cs
- OfTypeExpression.cs
- COM2PropertyDescriptor.cs
- WeakEventManager.cs
- SelectedPathEditor.cs
- HierarchicalDataSourceDesigner.cs
- EncryptedKey.cs
- LayoutEvent.cs
- RSAPKCS1KeyExchangeFormatter.cs
- SqlCaseSimplifier.cs
- ItemCollection.cs
- XmlAnyElementAttribute.cs
- Vector3DConverter.cs
- DBConcurrencyException.cs
- DataTable.cs
- KeyedCollection.cs
- oledbconnectionstring.cs
- AttachedPropertyBrowsableAttribute.cs
- ReliableSessionBindingElementImporter.cs
- Literal.cs
- CfgParser.cs
- SecurityTokenSerializer.cs
- ActivationServices.cs
- XmlDataDocument.cs
- QilReplaceVisitor.cs
- SoapExtensionStream.cs
- PropertyCollection.cs
- QueueProcessor.cs