PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/WCFWebApi/src/Microsoft.ApplicationServer.Http/Microsoft/ApplicationServer/Http/TrailingSlashModeHelper.cs

#
C# | 46 lines | 22 code | 4 blank | 20 comment | 3 complexity | 40021b96b6c82044c560e30d13a8320b MD5 | raw file
 1// <copyright>
 2//   Copyright (c) Microsoft Corporation.  All rights reserved.
 3// </copyright>
 4
 5namespace Microsoft.ApplicationServer.Http
 6{
 7    using System;
 8    using System.ComponentModel;
 9    using Microsoft.Server.Common;
10
11    /// <summary>
12    /// Helper class for validating <see cref="TrailingSlashMode"/> values.
13    /// </summary>
14    internal static class TrailingSlashModeHelper
15    {
16        private static readonly Type trailingSlashModeType = typeof(TrailingSlashMode);
17
18        /// <summary>
19        /// Determines whether the specified <paramref name="value"/> is defined by the <see cref="TrailingSlashMode"/>
20        /// enumeration.
21        /// </summary>
22        /// <param name="value">The value to verify.</param>
23        /// <returns>
24        /// <c>true</c> if the specified options is defined; otherwise, <c>false</c>.
25        /// </returns>
26        public static bool IsDefined(TrailingSlashMode value)
27        {
28            return value == TrailingSlashMode.AutoRedirect ||
29                   value == TrailingSlashMode.Ignore;
30        }
31
32        /// <summary>
33        /// Validates the specified <paramref name="value"/> and throws an <see cref="InvalidEnumArgumentException"/>
34        /// exception if not valid.
35        /// </summary>
36        /// <param name="value">The value to validate.</param>
37        /// <param name="parameterName">Name of the parameter to use if throwing exception.</param>
38        public static void Validate(TrailingSlashMode value, string parameterName)
39        {
40            if (!IsDefined(value))
41            {
42                throw Fx.Exception.AsError(new InvalidEnumArgumentException(parameterName, (int)value, trailingSlashModeType));
43            }
44        }
45    }
46}