forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringComparisonHelper.cs
More file actions
48 lines (45 loc) · 1.89 KB
/
Copy pathStringComparisonHelper.cs
File metadata and controls
48 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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
{
/// <summary>
/// Helper class for validating <see cref="StringComparison"/> values.
/// </summary>
internal static class StringComparisonHelper
{
/// <summary>
/// Determines whether the specified <paramref name="value"/> is defined by the <see cref="StringComparison"/>
/// enumeration.
/// </summary>
/// <param name="value">The value to verify.</param>
/// <returns>
/// <c>true</c> if the specified options is defined; otherwise, <c>false</c>.
/// </returns>
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;
}
/// <summary>
/// Validates the specified <paramref name="value"/> and throws an <see cref="ArgumentException"/>
/// exception if not valid.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="parameterName">Name of the parameter to use if throwing exception.</param>
public static void Validate(StringComparison value, string parameterName)
{
if (!IsDefined(value))
{
throw Error.InvalidEnumArgument(parameterName, (int)value, typeof(StringComparison));
}
}
}
}