-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
TestEnum.cs
86 lines (68 loc) · 3.02 KB
/
TestEnum.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Runtime.CompilerServices;
namespace Ardalis.SmartEnum.UnitTests
{
public class TestEnum : SmartEnum<TestEnum>
{
public static readonly TestEnum One = new TestEnum(1);
public static readonly TestEnum Two = new TestEnum(2);
public static readonly TestEnum Three = new TestEnum(3);
protected TestEnum(int value, [CallerMemberName] string name = null) : base(name, value)
{
}
}
public abstract class TestBaseEnum : SmartEnum<TestBaseEnum>
{
public static TestBaseEnum One;
internal TestBaseEnum(string name, int value) : base(name, value)
{
}
}
public sealed class TestDerivedEnum : TestBaseEnum
{
private TestDerivedEnum(string name, int value) : base(name, value)
{
}
static TestDerivedEnum()
{
One = new TestDerivedEnum(nameof(One), 1);
}
public static new TestBaseEnum FromValue(int value) =>
TestBaseEnum.FromValue(value);
public static new TestBaseEnum FromName(string name, bool ignoreCase = false) =>
TestBaseEnum.FromName(name, ignoreCase);
}
public class TestStringEnum : SmartEnum<TestStringEnum, string>
{
public static readonly TestStringEnum One = new TestStringEnum(nameof(One), nameof(One));
public static readonly TestStringEnum Two = new TestStringEnum(nameof(Two), nameof(Two));
public static readonly TestStringEnum Three = new TestStringEnum(nameof(Three), nameof(Three));
public static readonly TestStringEnum Empty = new TestStringEnum(nameof(Empty), string.Empty);
protected TestStringEnum(string name, string value) : base(name, value)
{
}
}
public class TestNullableStringEnum : SmartEnum<TestNullableStringEnum, string>
{
public static readonly TestNullableStringEnum None = new TestNullableStringEnum(nameof(None), null);
protected TestNullableStringEnum(string name, string value) : base(name, value)
{
}
}
public class TestBaseEnumWithDerivedValues : SmartEnum<TestBaseEnumWithDerivedValues>
{
protected TestBaseEnumWithDerivedValues(string name, int value) : base(name, value)
{ }
}
public class DerivedTestEnumWithValues1 : TestBaseEnumWithDerivedValues
{
public static readonly DerivedTestEnumWithValues1 A = new DerivedTestEnumWithValues1(nameof(A), 1);
public static readonly DerivedTestEnumWithValues1 B = new DerivedTestEnumWithValues1(nameof(B), 1);
private DerivedTestEnumWithValues1(string name, int value) : base(name, value) { }
}
public class DerivedTestEnumWithValues2 : TestBaseEnumWithDerivedValues
{
public static readonly DerivedTestEnumWithValues2 C = new DerivedTestEnumWithValues2(nameof(C), 1);
public static readonly DerivedTestEnumWithValues2 D = new DerivedTestEnumWithValues2(nameof(D), 1);
private DerivedTestEnumWithValues2(string name, int value) : base(name, value) { }
}
}