1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 3 using System.ComponentModel; 4 5 namespace System.Web.Http.SelfHost.Channels 6 { 7 /// <summary> 8 /// Internal helper class to validate <see cref="HttpBindingSecurityMode"/> enum values. 9 /// </summary> 10 internal static class HttpBindingSecurityModeHelper 11 { 12 private static readonly Type _httpBindingSecurityMode = typeof(HttpBindingSecurityMode); 13 14 /// <summary> 15 /// Determines whether the specified <paramref name="value"/> is defined by the <see cref="HttpBindingSecurityMode"/> 16 /// enumeration. 17 /// </summary> 18 /// <param name="value">The value to test.</param> 19 /// <returns><c>true</c> if <paramref name="value"/> is a valid <see cref="HttpBindingSecurityMode"/> value; otherwise<c> false</c>.</returns> IsDefined(HttpBindingSecurityMode value)20 public static bool IsDefined(HttpBindingSecurityMode value) 21 { 22 return value == HttpBindingSecurityMode.None || 23 value == HttpBindingSecurityMode.Transport || 24 value == HttpBindingSecurityMode.TransportCredentialOnly; 25 } 26 27 /// <summary> 28 /// Validates the specified <paramref name="value"/> and throws an <see cref="InvalidEnumArgumentException"/> 29 /// exception if not valid. 30 /// </summary> 31 /// <param name="value">The value to validate.</param> 32 /// <param name="parameterName">Name of the parameter to use if throwing exception.</param> Validate(HttpBindingSecurityMode value, string parameterName)33 public static void Validate(HttpBindingSecurityMode value, string parameterName) 34 { 35 if (!IsDefined(value)) 36 { 37 throw Error.InvalidEnumArgument(parameterName, (int)value, _httpBindingSecurityMode); 38 } 39 } 40 } 41 } 42