-
Notifications
You must be signed in to change notification settings - Fork 102
/
IEnumInfo.cs
174 lines (165 loc) · 8.94 KB
/
IEnumInfo.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#region License
// Copyright (c) 2016 Tyler Brinkley
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using EnumsNET.Numerics;
namespace EnumsNET
{
internal interface ICommonEnumInfo
{
#if ICONVERTIBLE
TypeCode TypeCode { get; }
#endif
Type UnderlyingType { get; }
bool IsFlagEnum { get; }
int GetMemberCount(EnumMemberSelection selection = EnumMemberSelection.All);
IEnumerable<string> GetNames(EnumMemberSelection selection = EnumMemberSelection.All);
}
internal interface IEnumInfo : ICommonEnumInfo
{
object AllFlags { get; }
string AsString(object value);
string AsString(object value, string format);
string AsString(object value, EnumFormat format);
string AsString(object value, EnumFormat format0, EnumFormat format1);
string AsString(object value, EnumFormat format0, EnumFormat format1, EnumFormat format2);
string AsString(object value, EnumFormat[] formats);
object RemoveFlags(object value, object otherFlags);
object CommonFlags(object value, object otherFlags);
int CompareTo(object value, object other);
bool Equals(object value, object other);
string Format(object value, string format);
string Format(object value, EnumFormat[] formats);
string FormatFlags(object value, string delimiter, EnumFormat[] formats);
EnumMember GetMember(object value);
EnumMember GetMember(string value, bool ignoreCase = false, EnumFormat[] formats = null);
IEnumerable<EnumMember> GetMembers(EnumMemberSelection selection = EnumMemberSelection.All);
IEnumerable<object> GetFlags(object value);
IEnumerable<EnumMember> GetFlagMembers(object value);
string GetName(object value);
object GetUnderlyingValue(object value);
IEnumerable<object> GetValues(EnumMemberSelection selection = EnumMemberSelection.All);
bool HasAllFlags(object value);
bool HasAllFlags(object value, object otherFlags);
bool HasAnyFlags(object value);
bool HasAnyFlags(object value, object otherFlags);
bool IsDefined(object value);
bool IsValid(object value, EnumValidation validation = EnumValidation.Default);
bool IsValidFlagCombination(object value);
object Parse(string value, bool ignoreCase, EnumFormat[] formats);
object ParseFlags(string value, bool ignoreCase, string delimiter, EnumFormat[] formats);
object CombineFlags(IEnumerable<object> flags);
object CombineFlags(object value, object otherFlags);
byte ToByte(object value);
object ToggleFlags(object value);
object ToggleFlags(object value, object otherFlags);
short ToInt16(object value);
int ToInt32(object value);
long ToInt64(object value);
object ToObject(ulong value, EnumValidation validation = EnumValidation.None);
object ToObject(object value, EnumValidation validation = EnumValidation.None);
object ToObject(long value, EnumValidation validation = EnumValidation.None);
sbyte ToSByte(object value);
ushort ToUInt16(object value);
uint ToUInt32(object value);
ulong ToUInt64(object value);
bool TryParse(string value, bool ignoreCase, out object result, EnumFormat[] formats);
bool TryParseFlags(string value, bool ignoreCase, string delimiter, out object result, EnumFormat[] formats);
bool TryToObject(ulong value, out object result, EnumValidation validation = EnumValidation.None);
bool TryToObject(object value, out object result, EnumValidation validation = EnumValidation.None);
bool TryToObject(long value, out object result, EnumValidation validation = EnumValidation.None);
object Validate(object value, string paramName, EnumValidation validation = EnumValidation.Default);
}
internal interface IEnumInfo<TEnum> : ICommonEnumInfo
{
TEnum AllFlags { get; }
string AsString(TEnum value);
string AsString(TEnum value, string format);
string AsString(TEnum value, EnumFormat format);
string AsString(TEnum value, EnumFormat format0, EnumFormat format1);
string AsString(TEnum value, EnumFormat format0, EnumFormat format1, EnumFormat format2);
string AsString(TEnum value, EnumFormat[] formats);
TEnum RemoveFlags(TEnum value, TEnum otherFlags);
TEnum CommonFlags(TEnum value, TEnum otherFlags);
int CompareTo(TEnum value, TEnum other);
bool Equals(TEnum value, TEnum other);
string Format(TEnum value, string format);
string Format(TEnum value, EnumFormat[] formats);
string FormatFlags(TEnum value, string delimiter = null, EnumFormat[] formats = null);
EnumMember<TEnum> GetMember(TEnum value);
EnumMember<TEnum> GetMember(string value, bool ignoreCase = false, EnumFormat[] formats = null);
IEnumerable<EnumMember<TEnum>> GetMembers(EnumMemberSelection selection = EnumMemberSelection.All);
IEnumerable<TEnum> GetFlags(TEnum value);
IEnumerable<EnumMember<TEnum>> GetFlagMembers(TEnum value);
int GetHashCode(TEnum value);
string GetName(TEnum value);
object GetUnderlyingValue(TEnum value);
IEnumerable<TEnum> GetValues(EnumMemberSelection selection = EnumMemberSelection.All);
bool HasAllFlags(TEnum value);
bool HasAllFlags(TEnum value, TEnum otherFlags);
bool HasAnyFlags(TEnum value);
bool HasAnyFlags(TEnum value, TEnum otherFlags);
bool IsDefined(TEnum value);
bool IsValid(TEnum value, EnumValidation validation = EnumValidation.Default);
bool IsValidFlagCombination(TEnum value);
TEnum Parse(string value, bool ignoreCase = false, EnumFormat[] formats = null);
TEnum ParseFlags(string value, bool ignoreCase = false, string delimiter = null, EnumFormat[] formats = null);
TEnum CombineFlags(IEnumerable<TEnum> flags);
TEnum CombineFlags(TEnum value, TEnum otherFlags);
TEnum CombineFlags(TEnum flag0, TEnum flag1, TEnum flag2);
TEnum CombineFlags(TEnum flag0, TEnum flag1, TEnum flag2, TEnum flag3);
TEnum CombineFlags(TEnum flag0, TEnum flag1, TEnum flag2, TEnum flag3, TEnum flag4);
byte ToByte(TEnum value);
TEnum ToggleFlags(TEnum value);
TEnum ToggleFlags(TEnum value, TEnum otherFlags);
short ToInt16(TEnum value);
int ToInt32(TEnum value);
long ToInt64(TEnum value);
TEnum ToObject(ulong value, EnumValidation validation = EnumValidation.None);
TEnum ToObject(object value, EnumValidation validation = EnumValidation.None);
TEnum ToObject(long value, EnumValidation validation = EnumValidation.None);
sbyte ToSByte(TEnum value);
ushort ToUInt16(TEnum value);
uint ToUInt32(TEnum value);
ulong ToUInt64(TEnum value);
bool TryParse(string value, bool ignoreCase, out TEnum result, EnumFormat[] formats = null);
bool TryParseFlags(string value, bool ignoreCase, string delimiter, out TEnum result, EnumFormat[] formats = null);
bool TryToObject(ulong value, out TEnum result, EnumValidation validation = EnumValidation.None);
bool TryToObject(object value, out TEnum result, EnumValidation validation = EnumValidation.None);
bool TryToObject(long value, out TEnum result, EnumValidation validation = EnumValidation.None);
TEnum Validate(TEnum value, string paramName, EnumValidation validation = EnumValidation.Default);
}
internal interface IEnumInfoInternal<TInt, TIntProvider>
where TInt : struct, IComparable<TInt>, IEquatable<TInt>
#if ICONVERTIBLE
, IConvertible
#endif
where TIntProvider : struct, INumericProvider<TInt>
{
bool HasCustomValidator { get; }
EnumMember CreateEnumMember(EnumMemberInternal<TInt, TIntProvider> member);
bool CustomValidate(TInt value);
}
}