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
- TransportContext.cs
- DockProviderWrapper.cs
- ThreadPool.cs
- Binding.cs
- CodeCommentStatement.cs
- SharedStream.cs
- NavigationPropertyEmitter.cs
- ExportException.cs
- BamlTreeMap.cs
- NavigationProgressEventArgs.cs
- PlatformNotSupportedException.cs
- EnumerableRowCollection.cs
- PackageRelationshipCollection.cs
- CaseInsensitiveComparer.cs
- ImageClickEventArgs.cs
- DisplayInformation.cs
- FtpWebResponse.cs
- Nullable.cs
- control.ime.cs
- FindCriteria.cs
- srgsitem.cs
- DeflateEmulationStream.cs
- DataView.cs
- ToolStripContentPanel.cs
- LocalValueEnumerator.cs
- HttpUnhandledOperationInvoker.cs
- HtmlTernaryTree.cs
- DataGridViewLayoutData.cs
- ReadOnlyDataSourceView.cs
- JpegBitmapEncoder.cs
- WindowsSolidBrush.cs
- Stroke.cs
- SymDocumentType.cs
- ConfigurationHelpers.cs
- InfoCardSchemas.cs
- XmlSchemaExternal.cs
- DataSourceSelectArguments.cs
- MissingMethodException.cs
- ImageIndexEditor.cs
- processwaithandle.cs
- SqlCrossApplyToCrossJoin.cs
- TraceEventCache.cs
- AssemblyResolver.cs
- WriteFileContext.cs
- NavigationProperty.cs
- StatusBarItem.cs
- LineVisual.cs
- TreeViewImageIndexConverter.cs
- DataServiceRequestException.cs
- AssemblyResourceLoader.cs
- WorkflowControlClient.cs
- QuaternionAnimation.cs
- HttpProfileBase.cs
- AutomationPatternInfo.cs
- EntityCommandDefinition.cs
- ConfigurationManager.cs
- ParamArrayAttribute.cs
- DependencyObjectValidator.cs
- TextChangedEventArgs.cs
- PrintController.cs
- MetadataItemCollectionFactory.cs
- ClipboardData.cs
- ContentOperations.cs
- ProfilePropertyNameValidator.cs
- Publisher.cs
- ZipIOBlockManager.cs
- SByteConverter.cs
- BooleanFacetDescriptionElement.cs
- NavigationProgressEventArgs.cs
- DoubleMinMaxAggregationOperator.cs
- BoolExpression.cs
- NameTable.cs
- DataGridViewIntLinkedList.cs
- SocketPermission.cs
- SystemResourceKey.cs
- ScrollBarRenderer.cs
- FloatUtil.cs
- SignatureResourcePool.cs
- SpellerStatusTable.cs
- ConfigurationStrings.cs
- SecUtil.cs
- StorageAssociationSetMapping.cs
- CompoundFileStreamReference.cs
- TreeViewEvent.cs
- LinqDataSourceInsertEventArgs.cs
- XmlSchemaSimpleTypeUnion.cs
- DataGridView.cs
- TreeBuilder.cs
- ConsoleCancelEventArgs.cs
- KeyValuePairs.cs
- AnnouncementInnerClientCD1.cs
- SafeProcessHandle.cs
- ScriptModule.cs
- CounterCreationData.cs
- UIElementParagraph.cs
- RadioButtonRenderer.cs
- DataControlFieldTypeEditor.cs
- XmlArrayItemAttributes.cs
- GroupBox.cs
- CultureSpecificCharacterBufferRange.cs