// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.ComponentModel;
using System.Web.Http;
namespace System.Net.Http.Formatting
{
///
/// Helper class for validating values.
///
internal static class StringComparisonHelper
{
///
/// Determines whether the specified is defined by the
/// enumeration.
///
/// The value to verify.
///
/// true if the specified options is defined; otherwise, false.
///
public static bool IsDefined(StringComparison value)
{
return value == StringComparison.CurrentCulture ||
value == StringComparison.CurrentCultureIgnoreCase ||
#if !NETFX_CORE
value == StringComparison.InvariantCulture ||
value == StringComparison.InvariantCultureIgnoreCase ||
#endif
value == StringComparison.Ordinal ||
value == StringComparison.OrdinalIgnoreCase;
}
///
/// Validates the specified and throws an
/// exception if not valid.
///
/// The value to validate.
/// Name of the parameter to use if throwing exception.
public static void Validate(StringComparison value, string parameterName)
{
if (!IsDefined(value))
{
throw Error.InvalidEnumArgument(parameterName, (int)value, typeof(StringComparison));
}
}
}
}