1 //------------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------------------------
4 
5 namespace System.ServiceModel.Configuration
6 {
7     using System.Collections;
8     using System.Configuration;
9     using System.Globalization;
10     using System.Collections.Generic;
11 
12     [ConfigurationCollection(typeof(EndpointBehaviorElement), AddItemName = ConfigurationStrings.Behavior)]
13     public sealed class EndpointBehaviorElementCollection : ServiceModelEnhancedConfigurationElementCollection<EndpointBehaviorElement>
14     {
EndpointBehaviorElementCollection()15         public EndpointBehaviorElementCollection()
16             : base(ConfigurationStrings.Behavior)
17         { }
18 
19         protected override bool ThrowOnDuplicate
20         {
21             get { return false; }
22         }
23 
GetElementKey(ConfigurationElement element)24         protected override Object GetElementKey(ConfigurationElement element)
25         {
26             if (element == null)
27             {
28                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
29             }
30 
31             EndpointBehaviorElement configElementKey = (EndpointBehaviorElement)element;
32             return configElementKey.Name;
33         }
34 
BaseAdd(ConfigurationElement element)35         protected override void BaseAdd(ConfigurationElement element)
36         {
37             if (null == element)
38             {
39                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
40             }
41 
42             EndpointBehaviorElement childEndpointBehaviorElement = element as EndpointBehaviorElement;
43             string endpointBehaviorElementName = childEndpointBehaviorElement.Name;
44             EndpointBehaviorElement parentEndpointBehaviorElement = this.BaseGet(endpointBehaviorElementName) as EndpointBehaviorElement;
45             List<BehaviorExtensionElement> parentExtensionElements = new List<BehaviorExtensionElement>();
46             if (parentEndpointBehaviorElement != null)
47             {
48                 foreach (BehaviorExtensionElement parentBehaviorElement in parentEndpointBehaviorElement)
49                 {
50                     parentExtensionElements.Add(parentBehaviorElement);
51                 }
52             }
53             childEndpointBehaviorElement.MergeWith(parentExtensionElements);
54             base.BaseAdd(childEndpointBehaviorElement);
55         }
56     }
57 }
58