| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Configuration; |
| | | 5 | | using System.Diagnostics.Contracts; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Configuration |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Binding-related Configuration elements use this base class for WCF-wide commonalities |
| | | 11 | | /// </summary> |
| | | 12 | | public abstract class ServiceModelConfigurationElement : ConfigurationElement |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Used by InitializeFrom() pattern to avoid writing default values to generated .config files. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <typeparam name="T"></typeparam> |
| | | 18 | | /// <param name="propertyName">ConfigurationProperty.Name for the configuration property to set</param> |
| | | 19 | | /// <param name="value">Value to set</param> |
| | | 20 | | protected void SetPropertyValueIfNotDefaultValue<T>(string propertyName, T value) |
| | | 21 | | { |
| | 0 | 22 | | ConfigurationProperty configurationProperty = Properties[propertyName]; |
| | | 23 | | Contract.Assert(configurationProperty != null, "Parameter 'propertyName' should be the name of a configurati |
| | | 24 | | Contract.Assert(configurationProperty.Type.IsAssignableFrom(typeof(T)), "Parameter 'propertyName' should be |
| | | 25 | | |
| | 0 | 26 | | if (!object.Equals(value, configurationProperty.DefaultValue)) |
| | | 27 | | { |
| | 0 | 28 | | SetPropertyValue(configurationProperty, value, /*ignoreLocks = */ false); |
| | | 29 | | } |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | } |
| | | 33 | | } |