Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- StrongName.cs
- GeometryGroup.cs
- WebSysDescriptionAttribute.cs
- SqlBulkCopyColumnMappingCollection.cs
- EventManager.cs
- XsltFunctions.cs
- PeerDuplexChannelListener.cs
- Char.cs
- WrapperEqualityComparer.cs
- Positioning.cs
- DBCSCodePageEncoding.cs
- Literal.cs
- hresults.cs
- WinFormsSpinner.cs
- PolicyException.cs
- ReadOnlyCollectionBase.cs
- MediaScriptCommandRoutedEventArgs.cs
- Base64Encoder.cs
- TextBox.cs
- RuntimeConfig.cs
- TextAutomationPeer.cs
- MethodImplAttribute.cs
- Timer.cs
- ApplicationException.cs
- ComUdtElementCollection.cs
- BitmapEffectGroup.cs
- SQLDateTime.cs
- LoginName.cs
- AccessibleObject.cs
- handlecollector.cs
- ToolStripDropDownClosingEventArgs.cs
- ApplicationSettingsBase.cs
- Executor.cs
- AnimationException.cs
- IndexObject.cs
- TokenBasedSet.cs
- EntityDataSourceViewSchema.cs
- ConnectionStringSettings.cs
- Workspace.cs
- SqlXml.cs
- TreeNodeMouseHoverEvent.cs
- AutomationIdentifierGuids.cs
- GenericPrincipal.cs
- EmbeddedMailObjectsCollection.cs
- DataKeyArray.cs
- LineVisual.cs
- SecurityPolicySection.cs
- LookupTables.cs
- CheckBoxAutomationPeer.cs
- UnknownBitmapEncoder.cs
- StyleBamlRecordReader.cs
- DetailsViewModeEventArgs.cs
- FocusManager.cs
- AppearanceEditorPart.cs
- CodePropertyReferenceExpression.cs
- DefaultValidator.cs
- OracleCommand.cs
- xsdvalidator.cs
- KeyedHashAlgorithm.cs
- DetailsViewPagerRow.cs
- LockingPersistenceProvider.cs
- TextServicesPropertyRanges.cs
- LineInfo.cs
- VerificationException.cs
- Suspend.cs
- XmlName.cs
- HostingEnvironmentSection.cs
- Lease.cs
- XamlDesignerSerializationManager.cs
- RemotingServices.cs
- ISAPIWorkerRequest.cs
- TextBoxDesigner.cs
- TableLayoutSettings.cs
- SystemResourceHost.cs
- MessageBodyMemberAttribute.cs
- BuildManager.cs
- AudioFormatConverter.cs
- RangeValueProviderWrapper.cs
- HtmlDocument.cs
- OuterGlowBitmapEffect.cs
- DragStartedEventArgs.cs
- SessionPageStatePersister.cs
- ping.cs
- CompoundFileStreamReference.cs
- ZipIOLocalFileBlock.cs
- sitestring.cs
- CommonDialog.cs
- WebServicesSection.cs
- commandenforcer.cs
- SettingsContext.cs
- DataBoundControlParameterTarget.cs
- RTLAwareMessageBox.cs
- Module.cs
- SelfIssuedSamlTokenFactory.cs
- BCLDebug.cs
- PropertyTabChangedEvent.cs
- WebPartTracker.cs
- ReadWriteObjectLock.cs
- EventWaitHandle.cs
- NativeMethods.cs