//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ namespace System.ServiceModel.Configuration { using System.Collections.ObjectModel; using System.Configuration; using System.ServiceModel; using System.Security; using System.Collections.Generic; using System.ServiceModel.Description; public partial class StandardEndpointCollectionElement : EndpointCollectionElement where TStandardEndpoint : ServiceEndpoint where TEndpointConfiguration : StandardEndpointElement, new () { [ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, Options = ConfigurationPropertyOptions.IsDefaultCollection)] public StandardEndpointElementCollection Endpoints { get { return (StandardEndpointElementCollection)base[ConfigurationStrings.DefaultCollectionName]; } } public override Type EndpointType { get { return typeof(TStandardEndpoint); } } public override ReadOnlyCollection ConfiguredEndpoints { get { List configuredEndpoints = new List(); foreach (StandardEndpointElement configuredEndpoint in this.Endpoints) { configuredEndpoints.Add(configuredEndpoint); } return new ReadOnlyCollection(configuredEndpoints); } } public override bool ContainsKey(string name) { StandardEndpointCollectionElement me = (StandardEndpointCollectionElement)this; #pragma warning suppress 56506 //Microsoft; me.Endpoints can never be null (underlying configuration system guarantees) return me.Endpoints.ContainsKey(name); } protected internal override StandardEndpointElement GetDefaultStandardEndpointElement() { return System.Activator.CreateInstance(); } protected internal override bool TryAdd(string name, ServiceEndpoint endpoint, Configuration config) { // The configuration item needs to understand the ServiceEndpointType && be of type ServiceEndpoint bool retval = (endpoint.GetType() == typeof(TStandardEndpoint)) && typeof(StandardEndpointElement).IsAssignableFrom(typeof(TEndpointConfiguration)); if (retval) { TEndpointConfiguration endpointConfig = new TEndpointConfiguration(); endpointConfig.Name = name; endpointConfig.InitializeFrom(endpoint); this.Endpoints.Add(endpointConfig); } return retval; } } }