Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Configuration / EndpointBehaviorElement.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4
5 namespace System.ServiceModel.Configuration
6 {
7     using System;
8     using System.ServiceModel;
9     using System.Collections.Generic;
10     using System.ComponentModel;
11     using System.Configuration;
12     using System.Globalization;
13     using System.Xml;
14
15     public partial class EndpointBehaviorElement : NamedServiceModelExtensionCollectionElement<BehaviorExtensionElement>
16     {
17         public EndpointBehaviorElement()
18             : this(null)
19         {
20         }
21
22         public EndpointBehaviorElement(string name)
23             : base(ConfigurationStrings.BehaviorExtensions, name)
24         {
25         }
26
27         // Verify that the behavior being added implements IEndpointBehavior
28         public override void Add(BehaviorExtensionElement element)
29         {
30             // If element is null, let base.Add() throw for consistency reasons
31             if (null != element)
32             {
33                 if (element is ClearBehaviorElement || element is RemoveBehaviorElement)
34                 {
35                     base.AddItem(element);
36                     return;
37                 }
38                 if (!typeof(System.ServiceModel.Description.IEndpointBehavior).IsAssignableFrom(element.BehaviorType))
39                 {
40 #pragma warning disable 56506 //Microsoft; element.ElementInformation is guaranteed to be non-null(System.Configuration)
41                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidEndpointBehaviorType,
42                         element.ConfigurationElementName,
43                         this.Name),
44                         element.ElementInformation.Source,
45                         element.ElementInformation.LineNumber));
46 #pragma warning restore
47                 }
48             }
49
50             base.Add(element);
51         }
52
53         // Verify that the behavior being added implements IEndpointBehavior
54         public override bool CanAdd(BehaviorExtensionElement element)
55         {
56             // If element is null, let base.CanAdd() throw for consistency reasons
57             if (null != element)
58             {
59                 if (element is ClearBehaviorElement || element is RemoveBehaviorElement)
60                 {
61                     return true;
62                 }
63                 if (!typeof(System.ServiceModel.Description.IEndpointBehavior).IsAssignableFrom(element.BehaviorType))
64                 {
65 #pragma warning disable 56506 //Microsoft; element.ElementInformation is guaranteed to be non-null(System.Configuration)
66                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidEndpointBehaviorType,
67                         element.ConfigurationElementName,
68                         this.Name),
69                         element.ElementInformation.Source,
70                         element.ElementInformation.LineNumber));
71 #pragma warning restore
72                 }
73             }
74
75             return base.CanAdd(element);
76         }
77     }
78 }