PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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