Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / security / system / security / authentication / ExtendedProtection / ServiceNameCollection.cs / 1305376 / ServiceNameCollection.cs
using System; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; namespace System.Security.Authentication.ExtendedProtection { // derived from ReadOnlyCollectionBase because it needs to be back ported to .Net 1.x [SuppressMessage("Microsoft.Design","CA1058:TypesShouldNotExtendCertainBaseTypes", Justification="changing this would be a breaking change; this code has already shipped")] [Serializable] public class ServiceNameCollection : ReadOnlyCollectionBase { public ServiceNameCollection(ICollection items) { if (items == null) { throw new ArgumentNullException("items"); } InnerList.AddRange(items); } public ServiceNameCollection Merge(string serviceName) { ArrayList newServiceNames = new ArrayList(); // be compatible with .Net 1.x; no generics newServiceNames.AddRange(this.InnerList); AddIfNew(newServiceNames, serviceName); ServiceNameCollection newCollection = new ServiceNameCollection(newServiceNames); return newCollection; } public ServiceNameCollection Merge(IEnumerable serviceNames) { ArrayList newServiceNames = new ArrayList(); // be compatible with .Net 1.x; no generics newServiceNames.AddRange(this.InnerList); // we have a pretty bad performance here: O(n^2), but since service name lists should // be small (<<50) and Merge() should not be called frequently, this shouldn't be an issue foreach (object item in serviceNames) { AddIfNew(newServiceNames, item as string); } ServiceNameCollection newCollection = new ServiceNameCollection(newServiceNames); return newCollection; } private void AddIfNew(ArrayList newServiceNames, string serviceName) { if (String.IsNullOrEmpty(serviceName)) { throw new ArgumentException(SR.GetString(SR.security_ServiceNameCollection_EmptyServiceName)); } if (!Contains(serviceName, newServiceNames)) { newServiceNames.Add(serviceName); } } private bool Contains(string searchServiceName, ICollection serviceNames) { Debug.Assert(serviceNames != null); Debug.Assert(!String.IsNullOrEmpty(searchServiceName)); bool found = false; foreach (string serviceName in serviceNames) { if (String.Compare(serviceName, searchServiceName, StringComparison.OrdinalIgnoreCase) == 0) { found = true; break; } } return found; } } } // 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
- SessionStateContainer.cs
- ValueUnavailableException.cs
- HttpVersion.cs
- ChangeConflicts.cs
- TypefaceCollection.cs
- Interlocked.cs
- FloatSumAggregationOperator.cs
- TextParagraphView.cs
- MultipartIdentifier.cs
- Form.cs
- ObjectDataSourceSelectingEventArgs.cs
- SizeChangedEventArgs.cs
- CollectionViewSource.cs
- ProfessionalColorTable.cs
- XhtmlTextWriter.cs
- MeasureItemEvent.cs
- HelloOperationAsyncResult.cs
- PkcsMisc.cs
- CompressStream.cs
- XdrBuilder.cs
- TextRenderer.cs
- JpegBitmapDecoder.cs
- PrimitiveXmlSerializers.cs
- PeerIPHelper.cs
- PeerApplicationLaunchInfo.cs
- InitializationEventAttribute.cs
- HttpCachePolicyElement.cs
- RequestCacheManager.cs
- CodeAttributeDeclaration.cs
- TaskExceptionHolder.cs
- EnumBuilder.cs
- MessageQueuePermission.cs
- Exception.cs
- DataGridViewRowCancelEventArgs.cs
- TextBox.cs
- EntityConnection.cs
- PrintDocument.cs
- FactoryMaker.cs
- AQNBuilder.cs
- Typography.cs
- TypeListConverter.cs
- WindowsScroll.cs
- CodeTypeReference.cs
- CodeIterationStatement.cs
- Request.cs
- MarkupExtensionSerializer.cs
- RuleEngine.cs
- ConfigurationManagerInternal.cs
- Semaphore.cs
- Socket.cs
- HttpFileCollection.cs
- ListItemsCollectionEditor.cs
- PermissionSetTriple.cs
- DetailsViewModeEventArgs.cs
- XPathDocumentNavigator.cs
- HtmlWindow.cs
- Image.cs
- DbParameterCollectionHelper.cs
- PhonemeConverter.cs
- SEHException.cs
- TraceInternal.cs
- ObjectList.cs
- Event.cs
- AppSettings.cs
- Win32PrintDialog.cs
- Size.cs
- Debug.cs
- ColumnClickEvent.cs
- ListViewItem.cs
- DataServices.cs
- DuplexSecurityProtocolFactory.cs
- SynchronizedPool.cs
- LinearKeyFrames.cs
- RenderOptions.cs
- XmlSortKey.cs
- ProcessThreadDesigner.cs
- ConfigurationPermission.cs
- RuntimeConfig.cs
- SelfIssuedTokenFactoryCredential.cs
- CharAnimationUsingKeyFrames.cs
- Int32.cs
- DoWhileDesigner.xaml.cs
- SafeProcessHandle.cs
- Certificate.cs
- InternalConfigHost.cs
- XmlDownloadManager.cs
- QueryOutputWriter.cs
- ArgumentOutOfRangeException.cs
- DataKeyCollection.cs
- DbgCompiler.cs
- Int32Rect.cs
- InertiaRotationBehavior.cs
- Binding.cs
- WebDescriptionAttribute.cs
- Pair.cs
- Source.cs
- DesignerVerb.cs
- ServerIdentity.cs
- ListControlDataBindingHandler.cs
- Padding.cs