-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIsInEnum.cs
29 lines (25 loc) · 983 Bytes
/
IsInEnum.cs
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
namespace AssertLibrary
{
using System;
using System.Diagnostics;
using System.Globalization;
public static partial class Assert
{
/// <summary>
/// Asserts that the given object is defined in the specified enum.
/// </summary>
/// <typeparam name="T">Enum to check if the given object is defined in it</typeparam>
/// <param name="value">Value to check if it's defined in the specified enum</param>
public static void IsInEnum<T>(object value)
{
if (value == null)
throw new ArgumentNullException("value");
var type = typeof(T);
Check(Enum.IsDefined(type, value), IsInEnumMessage(value, type));
}
private static string IsInEnumMessage(object value, Type type)
{
return string.Format(CultureInfo.CurrentCulture, "Couldn't find the value \"{0}\" in the enumeration \"{1}\".", value, type.Name);
}
}
}