FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MapWindow5/src/MW5.Shared/EnumHelper.cs at develop · MapWindow/MapWindow5 · GitHub
MapWindow
/
MapWindow5
Public
Notifications
You must be signed in to change notification settings
Fork
102
Star
308
Code
Issues
14
Pull requests
12
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MapWindow5
/
src
/
MW5.Shared
/
EnumHelper.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (55 loc) · 1.83 KB
Breadcrumbs
MapWindow5
/
src
/
MW5.Shared
/
EnumHelper.cs
Copy path
File metadata and controls
63 lines (55 loc) · 1.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Globalization
;
using
System
.
Linq
;
namespace
MW5
.
Shared
{
/// <summary>
/// Helper methods to work with enumrated values, including the support of converters
/// to provide string representation of these values in the UI.
/// </summary>
public
static
class
EnumHelper
{
private
static
readonly
Dictionary
<
Type
,
object
>
_dict
=
new
Dictionary
<
Type
,
object
>
(
)
;
public
static
void
RegisterConverter
<
T
>
(
IEnumConverter
<
T
>
converter
)
where
T
:
struct
,
IConvertible
{
var
t
=
new
T
(
)
;
_dict
.
Add
(
t
.
GetType
(
)
,
converter
)
;
}
public
static
Func
<
T
,
string
>
GetToStringFunction
<
T
>
(
)
where
T
:
struct
,
IConvertible
{
var
t
=
new
T
(
)
;
var
type
=
t
.
GetType
(
)
;
object
val
;
if
(
_dict
.
TryGetValue
(
type
,
out
val
)
)
{
var
converter
=
val
as
IEnumConverter
<
T
>
;
if
(
converter
!=
null
)
{
return
converter
.
GetString
;
}
}
return
null
;
}
public
static
IEnumerable
<
string
>
GetStrings
<
T
>
(
)
where
T
:
struct
,
IConvertible
{
var
t
=
new
T
(
)
;
var
type
=
t
.
GetType
(
)
;
var
values
=
Enum
.
GetValues
(
type
)
;
return
from
T
value
in
values
select
EnumToString
(
value
)
;
}
public
static
string
EnumToString
<
T
>
(
this
T
value
)
where
T
:
struct
,
IConvertible
{
var
fn
=
GetToStringFunction
<
T
>
(
)
;
if
(
fn
!=
null
)
{
return
fn
(
value
)
;
}
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
)
;
}
public
static
T
[
]
GetValues
<
T
>
(
)
{
return
Enum
.
GetValues
(
typeof
(
T
)
)
as
T
[
]
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL