forked from MaterialDesignInXAML/MaterialDesignInXamlToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnumDataAttribute.cs
31 lines (28 loc) · 1007 Bytes
/
EnumDataAttribute.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
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
namespace MaterialDesignThemes.Wpf.Tests
{
public class EnumDataAttribute : DataAttribute
{
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
ParameterInfo[] parameters = testMethod.GetParameters();
if (parameters.Length != 1 ||
!parameters[0].ParameterType.IsEnum)
{
throw new Exception($"{testMethod.DeclaringType?.FullName}.{testMethod.Name} must have a single enum parameter");
}
return GetDataImplementation(parameters[0].ParameterType);
static IEnumerable<object[]> GetDataImplementation(Type parameterType)
{
foreach (object enumValue in Enum.GetValues(parameterType).OfType<object>())
{
yield return new[] { enumValue };
}
}
}
}
}