-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEnumDisplay.cs
More file actions
38 lines (31 loc) · 889 Bytes
/
EnumDisplay.cs
File metadata and controls
38 lines (31 loc) · 889 Bytes
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
using System;
namespace KeePassDiceware
{
internal class EnumDisplay<T> : IEquatable<T>, IEquatable<EnumDisplay<T>> where T : Enum
{
public T Value { get; set; }
public string Description => Value.GetDescription();
public string Category => Value.GetCategory();
public EnumDisplay(T value)
{
Value = value;
}
public static implicit operator EnumDisplay<T>(T value)
{
var eld = new EnumDisplay<T>(value);
return eld;
}
public static implicit operator T(EnumDisplay<T> other)
{
return other.Value;
}
public override string ToString() => Description;
public bool Equals(T other) => other.Equals(Value);
public bool Equals(EnumDisplay<T> other) => other.Value.Equals(Value);
}
internal static class EnumDisplay
{
public static EnumDisplay<T> Create<T>(T value) where T : Enum
=> new(value);
}
}