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
- SHA512CryptoServiceProvider.cs
- NamespaceList.cs
- ParameterElement.cs
- TrackingProfileSerializer.cs
- CharUnicodeInfo.cs
- WebUtil.cs
- GregorianCalendarHelper.cs
- QuaternionAnimation.cs
- MobileControlBuilder.cs
- InputLangChangeEvent.cs
- GroupBoxAutomationPeer.cs
- odbcmetadatacolumnnames.cs
- XmlEnumAttribute.cs
- ApplicationFileCodeDomTreeGenerator.cs
- WebHttpBindingCollectionElement.cs
- HttpFileCollectionBase.cs
- ConnectionInterfaceCollection.cs
- SqlDataReaderSmi.cs
- PresentationSource.cs
- RijndaelManaged.cs
- String.cs
- SweepDirectionValidation.cs
- OutputWindow.cs
- MultipleFilterMatchesException.cs
- ErrorWrapper.cs
- ColumnPropertiesGroup.cs
- EnumType.cs
- PointConverter.cs
- ClickablePoint.cs
- SqlGatherProducedAliases.cs
- RuleAction.cs
- DbConvert.cs
- assertwrapper.cs
- Bold.cs
- ShaderEffect.cs
- CategoryValueConverter.cs
- SchemaTableColumn.cs
- GridLength.cs
- XmlTextAttribute.cs
- WorkflowViewElement.cs
- MatrixTransform.cs
- TimeoutHelper.cs
- SingleObjectCollection.cs
- TimeSpanStorage.cs
- EntityDesignerDataSourceView.cs
- WebPartConnectionsConnectVerb.cs
- WeakEventTable.cs
- Compilation.cs
- ExpressionBuilderContext.cs
- PageTheme.cs
- DataListCommandEventArgs.cs
- ZoneMembershipCondition.cs
- TimelineClockCollection.cs
- TreeViewAutomationPeer.cs
- EntityDataSourceColumn.cs
- CompilerInfo.cs
- ContactManager.cs
- UnsafeNativeMethods.cs
- CheckBox.cs
- EFDataModelProvider.cs
- ComponentConverter.cs
- Pointer.cs
- SecurityTokenResolver.cs
- ConfigXmlSignificantWhitespace.cs
- TextParentUndoUnit.cs
- MenuItem.cs
- CodeCompiler.cs
- OleAutBinder.cs
- ConstraintManager.cs
- CodeChecksumPragma.cs
- Marshal.cs
- MeshGeometry3D.cs
- GlobalizationSection.cs
- IdleTimeoutMonitor.cs
- ObjectDataProvider.cs
- BooleanProjectedSlot.cs
- DeclaredTypeValidatorAttribute.cs
- SQLGuid.cs
- MenuItem.cs
- SerializationInfoEnumerator.cs
- RIPEMD160.cs
- HttpHeaderCollection.cs
- FtpRequestCacheValidator.cs
- MLangCodePageEncoding.cs
- IItemProperties.cs
- Int32AnimationUsingKeyFrames.cs
- XPathConvert.cs
- DataReaderContainer.cs
- WorkerRequest.cs
- ThreadExceptionEvent.cs
- ParameterCollectionEditor.cs
- Monitor.cs
- WindowsGrip.cs
- SoundPlayer.cs
- SiteMapNodeCollection.cs
- LocatorGroup.cs
- XPathBinder.cs
- FileAuthorizationModule.cs
- DataListGeneralPage.cs
- CodeTypeParameterCollection.cs