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